Can fetch data from server
This commit is contained in:
parent
07b9f12fac
commit
917d08ac9f
@ -32,6 +32,8 @@
|
||||
|
||||
"indent": 2,
|
||||
"globals": {
|
||||
"afterEach": true,
|
||||
"beforeEach": true,
|
||||
"define": true,
|
||||
"describe": true,
|
||||
"expect": true,
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
define([
|
||||
'underscore',
|
||||
'marionette',
|
||||
'core/layout/module'
|
||||
], function AppDefine(Marionette, Layout) {
|
||||
], function AppDefine(_, Marionette, Layout) {
|
||||
'use strict';
|
||||
|
||||
var Application = Marionette.Application;
|
||||
@ -14,10 +15,17 @@ define([
|
||||
}
|
||||
|
||||
App.prototype = new Application();
|
||||
_.extend(App.prototype, {
|
||||
Layout: Layout,
|
||||
|
||||
App.prototype.initialize = function initialize() {
|
||||
this.module('layout', Layout);
|
||||
};
|
||||
initialize: function initialize(config) {
|
||||
config = config || {};
|
||||
if (config.Layout) {
|
||||
this.Layout = config.Layout;
|
||||
}
|
||||
this.module('layout', this.Layout);
|
||||
}
|
||||
});
|
||||
|
||||
return App;
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
define(['backbone'], function LayoutModelDefine(Backbone) {
|
||||
define(['underscore', 'backbone'], function LayoutModelDefine(_, Backbone) {
|
||||
'use strict';
|
||||
|
||||
var Model = Backbone.Model;
|
||||
@ -6,13 +6,17 @@ define(['backbone'], function LayoutModelDefine(Backbone) {
|
||||
function LayoutModel() {
|
||||
Model.apply(this, arguments);
|
||||
}
|
||||
|
||||
LayoutModel.prototype = new Model();
|
||||
|
||||
LayoutModel.prototype.defaults = function defaults() {
|
||||
_.extend(LayoutModel.prototype, {
|
||||
url: '/data/vendor.json',
|
||||
defaults: function defaults() {
|
||||
return {
|
||||
title: 'some title'
|
||||
};
|
||||
title: ''
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
return LayoutModel;
|
||||
});
|
||||
|
||||
@ -18,6 +18,7 @@ define([
|
||||
this.model = new this.Model(config.model);
|
||||
config.view.model = this.model;
|
||||
this.view = new this.View(config.view);
|
||||
this.model.fetch();
|
||||
this.view.render();
|
||||
}
|
||||
});
|
||||
|
||||
@ -5,7 +5,11 @@ define([
|
||||
'use strict';
|
||||
|
||||
var CoreLayout = Marionette.LayoutView.extend({
|
||||
template: template
|
||||
template: template,
|
||||
|
||||
modelEvents: {
|
||||
change: 'render'
|
||||
}
|
||||
});
|
||||
|
||||
return CoreLayout;
|
||||
|
||||
1
bin/deck
1
bin/deck
@ -24,6 +24,7 @@ app.get('/', function index(req, res) {
|
||||
fs.readFile(indexFile, {encoding: 'utf8'}, compileServe);
|
||||
});
|
||||
|
||||
app.use('/data', staticHandler('data'));
|
||||
app.use('/vendor', staticHandler('vendor'));
|
||||
app.use('/static', staticHandler('static'));
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ module.exports = function(config) {
|
||||
{pattern: 'test/**/!(test-main).js', included: false},
|
||||
{pattern: 'static/**/!(config).js', included: false},
|
||||
{pattern: 'static/**/*.map', included: false},
|
||||
{pattern: 'data/**/*.json', included: false},
|
||||
'static/style/main.css',
|
||||
'static/app/config.js',
|
||||
'test/test-main.js'
|
||||
|
||||
3
data/vendor.json
Normal file
3
data/vendor.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "from server"
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
define(['app'], function (App) {
|
||||
define(['marionette', 'app'], function (Marionette, App) {
|
||||
describe('App', function () {
|
||||
it('→ exits', function () {
|
||||
expect(new App()).not.toBeUndefined();
|
||||
@ -7,7 +7,8 @@ define(['app'], function (App) {
|
||||
describe('→ start()', function () {
|
||||
it('→ can be called', function () {
|
||||
expect(function noError() {
|
||||
(new App()).start();
|
||||
var app = new App({Layout: Marionette.Module});
|
||||
app.start();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
define([
|
||||
'backbone',
|
||||
'marionette',
|
||||
'core/layout/module'
|
||||
], function (Marionette, LayoutModule) {
|
||||
], function (Backbone, Marionette, LayoutModule) {
|
||||
|
||||
function MockModel() {
|
||||
Backbone.Model.apply(this, arguments);
|
||||
}
|
||||
MockModel.prototype = new Backbone.Model();
|
||||
MockModel.prototype.sync = function () {};
|
||||
|
||||
describe('LayoutModule', function () {
|
||||
it('→ exits', function () {
|
||||
var app = new Marionette.Application();
|
||||
@ -10,13 +18,26 @@ define([
|
||||
});
|
||||
|
||||
describe('→ onStart', function () {
|
||||
var app = null;
|
||||
var module = null;
|
||||
|
||||
beforeEach(function () {
|
||||
app = new Marionette.Application();
|
||||
module = new LayoutModule('layout', app, {});
|
||||
module.Model = MockModel;
|
||||
});
|
||||
|
||||
it('→ will render view', function () {
|
||||
var app = new Marionette.Application();
|
||||
var module = new LayoutModule('layout', app, {});
|
||||
spyOn(module.View.prototype, 'render');
|
||||
module.onStart();
|
||||
expect(module.View.prototype.render).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('→ will fetch model', function () {
|
||||
spyOn(module.Model.prototype, 'fetch');
|
||||
module.onStart();
|
||||
expect(module.Model.prototype.fetch).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
define(['core/layout/view'], function (LayoutView) {
|
||||
describe('→ LayoutView', function () {
|
||||
describe('LayoutView', function () {
|
||||
it('→ exists', function () {
|
||||
expect(new LayoutView()).not.toBeUndefined();
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user