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