forked from boranton/testcafe-workshop
👾 closures closures closures!
This commit is contained in:
parent
9c01a555b1
commit
3d0ac2f76c
@ -1,4 +1,5 @@
|
|||||||
/*global app, $on */
|
/*global app, $on */
|
||||||
|
'use strict';
|
||||||
require('todomvc-common/base.css');
|
require('todomvc-common/base.css');
|
||||||
require('todomvc-app-css/index.css');
|
require('todomvc-app-css/index.css');
|
||||||
require('./view');
|
require('./view');
|
||||||
@ -7,9 +8,6 @@ require('./controller');
|
|||||||
require('./model');
|
require('./model');
|
||||||
require('./store');
|
require('./store');
|
||||||
require('./template');
|
require('./template');
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a brand new Todo list.
|
* Sets up a brand new Todo list.
|
||||||
*
|
*
|
||||||
@ -34,4 +32,3 @@ require('./template');
|
|||||||
setView();
|
setView();
|
||||||
});
|
});
|
||||||
$on(window, 'hashchange', setView);
|
$on(window, 'hashchange', setView);
|
||||||
})();
|
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a model and view and acts as the controller between them
|
* Takes a model and view and acts as the controller between them
|
||||||
*
|
*
|
||||||
@ -265,4 +263,3 @@
|
|||||||
// Export to window
|
// Export to window
|
||||||
window.app = window.app || {};
|
window.app = window.app || {};
|
||||||
window.app.Controller = Controller;
|
window.app.Controller = Controller;
|
||||||
})(window);
|
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
/*global NodeList */
|
/*global NodeList */
|
||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Get element(s) by CSS selector:
|
// Get element(s) by CSS selector:
|
||||||
window.qs = function (selector, scope) {
|
window.qs = function (selector, scope) {
|
||||||
return (scope || document).querySelector(selector);
|
return (scope || document).querySelector(selector);
|
||||||
@ -49,4 +47,3 @@
|
|||||||
// Allow for looping on nodes by chaining:
|
// Allow for looping on nodes by chaining:
|
||||||
// qsa('.foo').forEach(function () {})
|
// qsa('.foo').forEach(function () {})
|
||||||
NodeList.prototype.forEach = Array.prototype.forEach;
|
NodeList.prototype.forEach = Array.prototype.forEach;
|
||||||
})(window);
|
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Model instance and hooks up the storage.
|
* Creates a new Model instance and hooks up the storage.
|
||||||
*
|
*
|
||||||
@ -19,7 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
Model.prototype.create = function (title, callback) {
|
Model.prototype.create = function (title, callback) {
|
||||||
title = title || '';
|
title = title || '';
|
||||||
callback = callback || function () {};
|
callback = callback || function () {
|
||||||
|
};
|
||||||
|
|
||||||
var newItem = {
|
var newItem = {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
@ -46,7 +45,8 @@
|
|||||||
*/
|
*/
|
||||||
Model.prototype.read = function (query, callback) {
|
Model.prototype.read = function (query, callback) {
|
||||||
var queryType = typeof query;
|
var queryType = typeof query;
|
||||||
callback = callback || function () {};
|
callback = callback || function () {
|
||||||
|
};
|
||||||
|
|
||||||
if (queryType === 'function') {
|
if (queryType === 'function') {
|
||||||
callback = query;
|
callback = query;
|
||||||
@ -117,4 +117,3 @@
|
|||||||
// Export to window
|
// Export to window
|
||||||
window.app = window.app || {};
|
window.app = window.app || {};
|
||||||
window.app.Model = Model;
|
window.app.Model = Model;
|
||||||
})(window);
|
|
||||||
|
|||||||
12
js/store.js
12
js/store.js
@ -1,7 +1,5 @@
|
|||||||
/*jshint eqeqeq:false */
|
/*jshint eqeqeq:false */
|
||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new client side storage object and will create an empty
|
* Creates a new client side storage object and will create an empty
|
||||||
* collection if no collection already exists.
|
* collection if no collection already exists.
|
||||||
@ -11,7 +9,8 @@
|
|||||||
* real life you probably would be making AJAX calls
|
* real life you probably would be making AJAX calls
|
||||||
*/
|
*/
|
||||||
function Store(name, callback) {
|
function Store(name, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {
|
||||||
|
};
|
||||||
|
|
||||||
this._dbName = name;
|
this._dbName = name;
|
||||||
|
|
||||||
@ -62,7 +61,8 @@
|
|||||||
* @param {function} callback The callback to fire upon retrieving data
|
* @param {function} callback The callback to fire upon retrieving data
|
||||||
*/
|
*/
|
||||||
Store.prototype.findAll = function (callback) {
|
Store.prototype.findAll = function (callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {
|
||||||
|
};
|
||||||
callback.call(this, JSON.parse(localStorage[this._dbName]).todos);
|
callback.call(this, JSON.parse(localStorage[this._dbName]).todos);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -78,7 +78,8 @@
|
|||||||
var data = JSON.parse(localStorage[this._dbName]);
|
var data = JSON.parse(localStorage[this._dbName]);
|
||||||
var todos = data.todos;
|
var todos = data.todos;
|
||||||
|
|
||||||
callback = callback || function () {};
|
callback = callback || function () {
|
||||||
|
};
|
||||||
|
|
||||||
// If an ID was actually given, find the item and update each property
|
// If an ID was actually given, find the item and update each property
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -137,4 +138,3 @@
|
|||||||
// Export to window
|
// Export to window
|
||||||
window.app = window.app || {};
|
window.app = window.app || {};
|
||||||
window.app.Store = Store;
|
window.app.Store = Store;
|
||||||
})(window);
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/*jshint laxbreak:true */
|
/*jshint laxbreak:true */
|
||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var htmlEscapes = {
|
var htmlEscapes = {
|
||||||
@ -111,4 +110,3 @@
|
|||||||
// Export to window
|
// Export to window
|
||||||
window.app = window.app || {};
|
window.app = window.app || {};
|
||||||
window.app.Template = Template;
|
window.app.Template = Template;
|
||||||
})(window);
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
/*global qs, qsa, $on, $parent, $delegate */
|
/*global qs, qsa, $on, $parent, $delegate */
|
||||||
require('./helpers');
|
|
||||||
(function (window) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
require('./helpers');
|
||||||
/**
|
/**
|
||||||
* View that abstracts away the browser's DOM completely.
|
* View that abstracts away the browser's DOM completely.
|
||||||
* It has two simple entry points:
|
* It has two simple entry points:
|
||||||
@ -216,4 +214,3 @@ require('./helpers');
|
|||||||
// Export to window
|
// Export to window
|
||||||
window.app = window.app || {};
|
window.app = window.app || {};
|
||||||
window.app.View = View;
|
window.app.View = View;
|
||||||
}(window));
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user