Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 让marionette.backbone与webpack热模块更换一起工作_Backbone.js_Webpack_Webpack Dev Server_Webpack Hmr - Fatal编程技术网

Backbone.js 让marionette.backbone与webpack热模块更换一起工作

Backbone.js 让marionette.backbone与webpack热模块更换一起工作,backbone.js,webpack,webpack-dev-server,webpack-hmr,Backbone.js,Webpack,Webpack Dev Server,Webpack Hmr,我使用了来自的一个示例项目来设置一个带有热模块替换的webpack项目。然后我设置了一个主干应用程序示例 //main.js 从“jquery”导入美元; 从“主干”导入主干; 从“./Router”导入路由器; window.app=window.app | |{}; const-app=新主干网.marionete.Application(); app.addRegions({content:'#content'}); app.on('start',()=>{ if(主干网历史) Back

我使用了来自的一个示例项目来设置一个带有热模块替换的webpack项目。然后我设置了一个主干应用程序示例

//main.js
从“jquery”导入美元;
从“主干”导入主干;
从“./Router”导入路由器;
window.app=window.app | |{};
const-app=新主干网.marionete.Application();
app.addRegions({content:'#content'});
app.on('start',()=>{
if(主干网历史)
Backbone.history.start({pushState:true})
}
);
app.addInitializer(()=>{
返回新路由器();
});
$(()=>{app.start()});
//HMR
如果(模块热){
module.hot.accept();

}
这有点诡计,但你可以让它与主干网一起工作。一篇博客文章很有趣。(免责声明,我写的)

简言之,您需要明确地告诉您的父视图您可以接受热重新加载,然后重新-
require
该新的热重新加载视图,关闭现有的子视图,并重新渲染它。下面的示例使用了符号,但相同的基本原理适用于木偶或香草主干

/* parent.view.js */
var ChildView = require('./child.view.js');
var ParentView = AmpersandView.extend({
    template : require('path/to/template.hbs')

    initialize: function(){
        var self = this;
        if(module.hot){
            module.hot.accept('./child.view.js', function(){
                // re-require your child view, this will give you the new hot-reloaded child view
                var NewChildView = require('./child.view.js');
                // Remove the old view.  In ampersand you just call 'remove'
                self.renderChildView(NewChildView);
            });
        }
    },

    renderChildView(View){
        if(this.child){
            this.child.remove();
        }
        // use passed in view
        var childView = new View({
            model: this.model
        });
        this.child = this.renderSubview(childView, this.query('.container'));
    } 

    render: function(){
        this.renderWithTemplate(this);
        renderChildView(ChildView);
        return this;
    }
});

```

这有点诡计,但你可以让它与主干网一起工作。一篇博客文章很有趣。(免责声明,我写的)

简言之,您需要明确地告诉您的父视图您可以接受热重新加载,然后重新-
require
该新的热重新加载视图,关闭现有的子视图,并重新渲染它。下面的示例使用了符号,但相同的基本原理适用于木偶或香草主干

/* parent.view.js */
var ChildView = require('./child.view.js');
var ParentView = AmpersandView.extend({
    template : require('path/to/template.hbs')

    initialize: function(){
        var self = this;
        if(module.hot){
            module.hot.accept('./child.view.js', function(){
                // re-require your child view, this will give you the new hot-reloaded child view
                var NewChildView = require('./child.view.js');
                // Remove the old view.  In ampersand you just call 'remove'
                self.renderChildView(NewChildView);
            });
        }
    },

    renderChildView(View){
        if(this.child){
            this.child.remove();
        }
        // use passed in view
        var childView = new View({
            model: this.model
        });
        this.child = this.renderSubview(childView, this.query('.container'));
    } 

    render: function(){
        this.renderWithTemplate(this);
        renderChildView(ChildView);
        return this;
    }
});

```

主干网似乎不支持HMR开箱即用,必须添加代码来处理重新加载视图,类似于react hot loader的工作方式主干网似乎不支持HMR开箱即用,必须添加代码来处理重新加载视图,类似于react hot loader的工作方式尼斯博文!该博客帖子的链接已断开-(很好的博文!到博文的链接已断开。)-(