Can fetch data from server

master
Buddy Sandidge 10 years ago
parent 07b9f12fac
commit 917d08ac9f

@ -32,6 +32,8 @@
"indent": 2, "indent": 2,
"globals": { "globals": {
"afterEach": true,
"beforeEach": true,
"define": true, "define": true,
"describe": true, "describe": true,
"expect": true, "expect": true,

@ -1,7 +1,8 @@
define([ define([
'underscore',
'marionette', 'marionette',
'core/layout/module' 'core/layout/module'
], function AppDefine(Marionette, Layout) { ], function AppDefine(_, Marionette, Layout) {
'use strict'; 'use strict';
var Application = Marionette.Application; var Application = Marionette.Application;
@ -14,10 +15,17 @@ define([
} }
App.prototype = new Application(); App.prototype = new Application();
_.extend(App.prototype, {
Layout: Layout,
App.prototype.initialize = function initialize() { initialize: function initialize(config) {
this.module('layout', Layout); config = config || {};
}; if (config.Layout) {
this.Layout = config.Layout;
}
this.module('layout', this.Layout);
}
});
return App; return App;
}); });

@ -1,4 +1,4 @@
define(['backbone'], function LayoutModelDefine(Backbone) { define(['underscore', 'backbone'], function LayoutModelDefine(_, Backbone) {
'use strict'; 'use strict';
var Model = Backbone.Model; var Model = Backbone.Model;
@ -6,13 +6,17 @@ define(['backbone'], function LayoutModelDefine(Backbone) {
function LayoutModel() { function LayoutModel() {
Model.apply(this, arguments); Model.apply(this, arguments);
} }
LayoutModel.prototype = new Model(); LayoutModel.prototype = new Model();
LayoutModel.prototype.defaults = function defaults() { _.extend(LayoutModel.prototype, {
return { url: '/data/vendor.json',
title: 'some title' defaults: function defaults() {
}; return {
}; title: ''
};
}
});
return LayoutModel; return LayoutModel;
}); });

@ -18,6 +18,7 @@ define([
this.model = new this.Model(config.model); this.model = new this.Model(config.model);
config.view.model = this.model; config.view.model = this.model;
this.view = new this.View(config.view); this.view = new this.View(config.view);
this.model.fetch();
this.view.render(); this.view.render();
} }
}); });

@ -5,7 +5,11 @@ define([
'use strict'; 'use strict';
var CoreLayout = Marionette.LayoutView.extend({ var CoreLayout = Marionette.LayoutView.extend({
template: template template: template,
modelEvents: {
change: 'render'
}
}); });
return CoreLayout; return CoreLayout;

@ -24,6 +24,7 @@ app.get('/', function index(req, res) {
fs.readFile(indexFile, {encoding: 'utf8'}, compileServe); fs.readFile(indexFile, {encoding: 'utf8'}, compileServe);
}); });
app.use('/data', staticHandler('data'));
app.use('/vendor', staticHandler('vendor')); app.use('/vendor', staticHandler('vendor'));
app.use('/static', staticHandler('static')); app.use('/static', staticHandler('static'));

@ -15,6 +15,7 @@ module.exports = function(config) {
{pattern: 'test/**/!(test-main).js', included: false}, {pattern: 'test/**/!(test-main).js', included: false},
{pattern: 'static/**/!(config).js', included: false}, {pattern: 'static/**/!(config).js', included: false},
{pattern: 'static/**/*.map', included: false}, {pattern: 'static/**/*.map', included: false},
{pattern: 'data/**/*.json', included: false},
'static/style/main.css', 'static/style/main.css',
'static/app/config.js', 'static/app/config.js',
'test/test-main.js' 'test/test-main.js'

@ -0,0 +1,3 @@
{
"title": "from server"
}

@ -1,4 +1,4 @@
define(['app'], function (App) { define(['marionette', 'app'], function (Marionette, App) {
describe('App', function () { describe('App', function () {
it('→ exits', function () { it('→ exits', function () {
expect(new App()).not.toBeUndefined(); expect(new App()).not.toBeUndefined();
@ -7,7 +7,8 @@ define(['app'], function (App) {
describe('→ start()', function () { describe('→ start()', function () {
it('→ can be called', function () { it('→ can be called', function () {
expect(function noError() { expect(function noError() {
(new App()).start(); var app = new App({Layout: Marionette.Module});
app.start();
}).not.toThrow(); }).not.toThrow();
}); });
}); });

@ -1,7 +1,15 @@
define([ define([
'backbone',
'marionette', 'marionette',
'core/layout/module' '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 () { describe('LayoutModule', function () {
it('→ exits', function () { it('→ exits', function () {
var app = new Marionette.Application(); var app = new Marionette.Application();
@ -10,13 +18,26 @@ define([
}); });
describe('→ onStart', function () { 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 () { it('→ will render view', function () {
var app = new Marionette.Application();
var module = new LayoutModule('layout', app, {});
spyOn(module.View.prototype, 'render'); spyOn(module.View.prototype, 'render');
module.onStart(); module.onStart();
expect(module.View.prototype.render).toHaveBeenCalled(); 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) { define(['core/layout/view'], function (LayoutView) {
describe('LayoutView', function () { describe('LayoutView', function () {
it('→ exists', function () { it('→ exists', function () {
expect(new LayoutView()).not.toBeUndefined(); expect(new LayoutView()).not.toBeUndefined();
}); });

Loading…
Cancel
Save