Comparing version 0.0.5 to 0.1.0
{ | ||
"name": "cmd.js", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "A chainable utility toolkit for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,2 @@ # cmd.js | ||
[![NPM](https://nodei.co/npm/cmd.js.png?downloads=true&stars=true)](https://nodei.co/npm/cmd.js/) | ||
| ||
[![NPM](https://nodei.co/npm-dl/cmd.js.png?months=6&height=2)](https://nodei.co/npm/cmd.js/) | ||
@@ -81,3 +80,3 @@ | ||
This project is built with [gulp](http://gulpjs.com/). Make all changes/additions in `lib/*.js` while running `make build-watch` from the command line. | ||
This project is built with [gulp](http://gulpjs.com/). Make all changes/additions in `src/lib/*.js` while running `make build-watch` from the command line. | ||
@@ -84,0 +83,0 @@ # API Reference |
@@ -6,3 +6,2 @@ # cmd.js | ||
[![NPM](https://nodei.co/npm/cmd.js.png?downloads=true&stars=true)](https://nodei.co/npm/cmd.js/) | ||
| ||
[![NPM](https://nodei.co/npm-dl/cmd.js.png?months=6&height=2)](https://nodei.co/npm/cmd.js/) | ||
@@ -81,3 +80,3 @@ | ||
This project is built with [gulp](http://gulpjs.com/). Make all changes/additions in `lib/*.js` while running `make build-watch` from the command line. | ||
This project is built with [gulp](http://gulpjs.com/). Make all changes/additions in `src/lib/*.js` while running `make build-watch` from the command line. | ||
@@ -84,0 +83,0 @@ # API Reference |
118
src/cmd.js
@@ -25,5 +25,5 @@ /** | ||
var plugins = [ | ||
'alert', 'compare', 'exists', 'extend', 'filter', | ||
'format', 'join', 'log', 'logger', 'lower', 'obj', 'pluck', | ||
'push', 'sort', 'switch', 'upper', 'view' | ||
'alert', 'compare', 'copy', 'exists', 'extend', 'filter', 'format', 'join', | ||
'log', 'logger', 'lower', 'max', 'min', 'obj', 'pluck', 'product', | ||
'push', 'sort', 'sum', 'switch', 'title', 'upper', 'view' | ||
]; | ||
@@ -44,7 +44,11 @@ return plugins.forEach(function (name) { | ||
if (plugin.export) { | ||
plugin.export(self); | ||
} | ||
if (plugin.all) { | ||
self.all(name, plugin.all, plugin.args); | ||
self.all(name, plugin.all, plugin); | ||
} | ||
else if (plugin.each) { | ||
self.each(name, plugin.each, plugin.args); | ||
self.each(name, plugin.each, plugin); | ||
} | ||
@@ -61,3 +65,3 @@ else if (plugin.raw) { | ||
*/ | ||
Command.prototype.all = function cmdAll(name, fn, args) { | ||
Command.prototype.all = function cmdAll(name, fn, plugin) { | ||
if (typeof fn !== 'function') { | ||
@@ -68,14 +72,48 @@ throw new Error('cmd.all(name, fn), fn was not a function, got ' + typeof fn); | ||
Command.prototype.__defineGetter__(name, function () { | ||
var self = this; | ||
if (Array.isArray(args)) { | ||
return this.getArgs(name, 'vals', function (vals) { | ||
/** | ||
* Handle the case where plugin.args is defined | ||
*/ | ||
if (Array.isArray(plugin.args)) { | ||
return self.getArgs(name, 'vals', function (vals) { | ||
return fn(plugin.args, vals); | ||
}); | ||
} | ||
/** | ||
* Values loader | ||
*/ | ||
var valsLoader = function (args) { | ||
return self.getArgs(name, 'vals', function (vals) { | ||
return fn(args, vals); | ||
}.bind(this)); | ||
}); | ||
}; | ||
/** | ||
* Expect the arguments to be provided in the form cmd.x(...args...)(...vals...) | ||
* but still allow default argSets to be used | ||
*/ | ||
var argsLoader = self.getArgs(name, 'args', function (args) { | ||
return valsLoader(args); | ||
}); | ||
/** | ||
* To syntax to avoid merging array arguments, just use raw arguments | ||
*/ | ||
argsLoader.__defineGetter__('to', function () { | ||
return function rawArgsLoader() { | ||
return valsLoader(Array.prototype.slice.call(arguments)); | ||
}; | ||
}) | ||
if (typeof plugin.argSets === 'object' && plugin.argSets) { | ||
Object.keys(plugin.argSets).forEach(function (key) { | ||
argsLoader.__defineGetter__(key, function () { | ||
return valsLoader(plugin.argSets[key]); | ||
}); | ||
}); | ||
} | ||
return this.getArgs(name, 'args', function (args) { | ||
return this.getArgs(name, 'vals', function (vals) { | ||
return fn(args, vals); | ||
}.bind(this)); | ||
}.bind(this)); | ||
return argsLoader; | ||
}); | ||
@@ -90,3 +128,3 @@ | ||
*/ | ||
Command.prototype.each = function cmdEach(name, fn, args) { | ||
Command.prototype.each = function cmdEach(name, fn, plugin) { | ||
if (typeof fn !== 'function') { | ||
@@ -97,18 +135,52 @@ throw new Error('cmd.each(name, fn), fn was not a function, got ' + typeof fn); | ||
Command.prototype.__defineGetter__(name, function () { | ||
var self = this; | ||
if (Array.isArray(args)) { | ||
return this.getArgs(name, 'vals', function (vals) { | ||
/** | ||
* Handle the case where plugin.args is defined | ||
*/ | ||
if (Array.isArray(plugin.args)) { | ||
return self.getArgs(name, 'vals', function (vals) { | ||
return vals.map(function (val) { | ||
return fn(args, val); | ||
return fn(plugin.args, val); | ||
}); | ||
}.bind(this)); | ||
}); | ||
} | ||
return this.getArgs(name, 'args', function (args) { | ||
return this.getArgs(name, 'vals', function (vals) { | ||
/** | ||
* Values loader | ||
*/ | ||
var valsLoader = function (args) { | ||
return self.getArgs(name, 'vals', function (vals) { | ||
return vals.map(function (val) { | ||
return fn(args, val); | ||
}); | ||
}.bind(this)); | ||
}.bind(this)); | ||
}); | ||
}; | ||
/** | ||
* Expect the arguments to be provided in the form cmd.x(...args...)(...vals...) | ||
* but still allow default argSets to be used | ||
*/ | ||
var argsLoader = self.getArgs(name, 'args', function (args) { | ||
return valsLoader(args); | ||
}); | ||
/** | ||
* To syntax to avoid merging array arguments, just use raw arguments | ||
*/ | ||
argsLoader.__defineGetter__('to', function () { | ||
return function rawArgsLoader() { | ||
return valsLoader(Array.prototype.slice.call(arguments)); | ||
}; | ||
}) | ||
if (typeof plugin.argSets === 'object' && plugin.argSets) { | ||
Object.keys(plugin.argSets).forEach(function (key) { | ||
argsLoader.__defineGetter__(key, function () { | ||
return valsLoader(plugin.argSets[key]); | ||
}); | ||
}); | ||
} | ||
return argsLoader; | ||
}); | ||
@@ -115,0 +187,0 @@ |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: alert('a') - shows an alert | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return typeof alert === 'function' ? alert(val) : undefined; | ||
this.export = function () { | ||
/** | ||
* Command: alert('a') - shows an alert | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return typeof alert === 'function' ? alert(val) : undefined; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].alert = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: compare(6, 3) === -1 | ||
* @author Nate Ferrero | ||
*/ | ||
this.raw = function (_a, _b) { | ||
var compare = function (a, b) { | ||
if (typeof a !== typeof b) { | ||
return compare(typeof a, typeof b); | ||
} | ||
switch (typeof a) { | ||
case 'number': | ||
return a - b; | ||
case 'string': | ||
case 'boolean': | ||
if (a === b) { | ||
this.export = function () { | ||
/** | ||
* Command: compare(6, 3) === -1 | ||
* @author Nate Ferrero | ||
*/ | ||
this.raw = function (_a, _b) { | ||
var compare = function (a, b) { | ||
if (typeof a !== typeof b) { | ||
return compare(typeof a, typeof b); | ||
} | ||
switch (typeof a) { | ||
case 'number': | ||
return a - b; | ||
case 'string': | ||
case 'boolean': | ||
if (a === b) { | ||
return 0; | ||
} | ||
return a > b ? 1 : -1; | ||
default: | ||
return 0; | ||
} | ||
return a > b ? 1 : -1; | ||
default: | ||
return 0; | ||
} | ||
}; | ||
if (!Array.isArray(_a)) { | ||
return compare(_a, _b); | ||
} | ||
}; | ||
if (!Array.isArray(_a)) { | ||
return compare(_a, _b); | ||
} | ||
var result = 0; | ||
var result = 0; | ||
for (var i = 0; i < _a.length; i++) { | ||
result = compare(_a[i], _b[i]); | ||
if (result !== 0) { | ||
break; | ||
for (var i = 0; i < _a.length; i++) { | ||
result = compare(_a[i], _b[i]); | ||
if (result !== 0) { | ||
break; | ||
} | ||
} | ||
} | ||
return result; | ||
return result; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].compare = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: exists(null) === [false] | ||
* exists.raw(null) === false | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return val !== null && val !== undefined; | ||
this.export = function () { | ||
/** | ||
* Command: exists(null) === [false] | ||
* exists.raw(null) === false | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return val !== null && val !== undefined; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].exists = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: extend({b: 2}, {c: 3})({a: 1}) === [{a: 1, b: 2, c: 3}] | ||
* Extends each val with each args | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
args.forEach(function (arg) { | ||
Object.keys(arg).forEach(function (key) { | ||
if (arg.hasOwnProperty(key)) { | ||
val[key] = arg[key]; | ||
} | ||
this.export = function () { | ||
/** | ||
* Command: extend({b: 2}, {c: 3})({a: 1}) === [{a: 1, b: 2, c: 3}] | ||
* Extends each val with each args | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
args.forEach(function (arg) { | ||
Object.keys(arg).forEach(function (key) { | ||
if (arg.hasOwnProperty(key)) { | ||
val[key] = arg[key]; | ||
} | ||
}) | ||
}) | ||
}) | ||
return val; | ||
return val; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].extend = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: filter(function (x) { | ||
* return x >= 3; | ||
* })(1, 2, 3) === [3] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return vals.filter(function (val) { | ||
var len = args.length; | ||
var i = -1; | ||
while (++i < len) { | ||
if (!(args[i].raw || args[i])(val)) { | ||
return false; | ||
this.export = function () { | ||
/** | ||
* Command: filter(function (x) { | ||
* return x >= 3; | ||
* })(1, 2, 3) === [3] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return vals.filter(function (val) { | ||
var len = args.length; | ||
var i = -1; | ||
while (++i < len) { | ||
if (!(args[i].raw || args[i])(val)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
}); | ||
return true; | ||
}); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].filter = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: format('a: {}')('A') === ['a: A'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
vals.forEach(function (val) { | ||
arg = arg.replace('{}', val); | ||
this.export = function () { | ||
/** | ||
* Command: format('a: {}')('A') === ['a: A'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
vals.forEach(function (val) { | ||
arg = arg.replace('{}', val); | ||
}); | ||
return arg; | ||
}); | ||
return arg; | ||
}); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].format = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: join('-')(1, 2, 3) === ['1-2-3'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
return vals.join(arg); | ||
}); | ||
this.export = function () { | ||
/** | ||
* Command: join('-')(1, 2, 3) === ['1-2-3'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
return vals.join(arg); | ||
}); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].join = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: log('a') - logs to console | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return console.log(val); | ||
this.export = function (cmd) { | ||
/** | ||
* Command: log('a') - logs to console | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
if (cmd.$logInterface) { | ||
cmd.$logInterface.log.call(cmd.$logInterface, val); | ||
} | ||
else { | ||
console.log(val); | ||
} | ||
return val; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].log = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: logger(function (a) { | ||
* return 10 * a; | ||
* }, 1)(1, 2, 3) - logs to console: | ||
* 10 1 | ||
* 20 1 | ||
* 30 1 | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var logs = []; | ||
args.forEach(function (arg) { | ||
var log = typeof arg === 'function' ? arg(val) : arg; | ||
if (Array.isArray(log)) { | ||
Array.prototype.push.apply(logs, log); | ||
this.export = function (cmd) { | ||
/** | ||
* Command: logger(function (a) { | ||
* return 10 * a; | ||
* }, 1)(1, 2, 3) - logs to console: | ||
* 10 1 | ||
* 20 1 | ||
* 30 1 | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var logs = []; | ||
args.forEach(function (arg) { | ||
var log = typeof arg === 'function' ? arg(val) : arg; | ||
if (Array.isArray(log)) { | ||
Array.prototype.push.apply(logs, log); | ||
} | ||
else { | ||
logs.push(log); | ||
} | ||
}); | ||
if (cmd.$loggerInterface) { | ||
cmd.$loggerInterface.log.apply(cmd.$loggerInterface, logs); | ||
} | ||
else { | ||
logs.push(log); | ||
console.log.apply(console, logs); | ||
} | ||
}); | ||
console.log.apply(console, logs); | ||
return val; | ||
return val; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].logger = {} : this); | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Command: lower('A') === ['a'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return ('' + val).toLowerCase(); | ||
this.export = function () { | ||
/** | ||
* Command: lower('A') === ['a'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return ('' + val).toLowerCase(); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].lower = {} : this); | ||
(function () { | ||
'use strict'; | ||
/** | ||
* Command: obj('a', 'b')(1, 2) === [{a: 1, b: 2}] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
var obj = {}; | ||
args.forEach(function (arg, i) { | ||
if (i in vals) { | ||
obj[arg] = vals[i]; | ||
} | ||
}); | ||
return [obj]; | ||
this.export = function () { | ||
/** | ||
* Command: obj('a', 'b')(1, 2) === [{a: 1, b: 2}] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
var obj = {}; | ||
args.forEach(function (arg, i) { | ||
if (i in vals) { | ||
obj[arg] = vals[i]; | ||
} | ||
}); | ||
return [obj]; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].obj = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: pluck('color')({color: 'red'}) === ['red'] | ||
* pluck('color').raw({color: 'red'}) === 'red' | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var exists = cmd.exists.raw; | ||
args.forEach(function (arg) { | ||
if (exists(val)) { | ||
val = val[arg]; | ||
} | ||
}); | ||
return val; | ||
this.export = function (cmd) { | ||
/** | ||
* Command: pluck('color')({color: 'red'}) === ['red'] | ||
* pluck('color').raw({color: 'red'}) === 'red' | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var exists = cmd.exists.raw; | ||
args.forEach(function (arg) { | ||
if (exists(val)) { | ||
val = val[arg]; | ||
} | ||
}); | ||
return val; | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].pluck = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: push(1)(2) === [2, 1] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
arg.push.apply(arg, vals); | ||
}); | ||
this.export = function () { | ||
/** | ||
* Command: push.to([1])(2) -> [1, 2] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return args.map(function (arg) { | ||
arg.push.apply(arg, vals); | ||
}); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].push = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: sort(function (val) { | ||
* return val; | ||
* })(3, 2, 1) === [1, 2, 3] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
return vals.sort(function (a, b) { | ||
if (!args.length) { | ||
return cmd.compare(a, b); | ||
this.export = function (cmd) { | ||
/** | ||
* Dependencies | ||
*/ | ||
cmd.use('compare', 'copy'); | ||
/** | ||
* Command: sort(function (val) { | ||
* return val; | ||
* })(3, 2, 1) === [1, 2, 3] | ||
* @author Nate Ferrero | ||
*/ | ||
this.all = function (args, vals) { | ||
var direction = 1; | ||
var local = cmd.copy(args); | ||
if (local && local.length && typeof local[0] === 'number') { | ||
direction = local.shift(); | ||
} | ||
return cmd.compare( | ||
args.map(function (arg) { | ||
return arg(a); | ||
}), | ||
args.map(function (arg) { | ||
return arg(b); | ||
}) | ||
); | ||
}); | ||
if (direction === 0) { | ||
return vals; | ||
} | ||
return vals.sort(function (a, b) { | ||
if (!local.length) { | ||
return direction * cmd.compare(a, b); | ||
} | ||
return direction * cmd.compare( | ||
local.map(function (arg) { | ||
return arg(a); | ||
}), | ||
local.map(function (arg) { | ||
return arg(b); | ||
}) | ||
); | ||
}); | ||
}; | ||
this.argSets = { | ||
/** | ||
* Argset for ascending sort | ||
*/ | ||
asc: [], | ||
/** | ||
* Argset for descending sort | ||
*/ | ||
desc: [-1] | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].sort = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: switch(function (when, val) { | ||
* when(val == 1, function () { return 'a'; }); | ||
* when(val == 2, function () { return 'b'; }); | ||
* when(val >= 3, function () { return 'c'; }); | ||
* })(1, 2, 3) === ['a', 'b', 'c'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var cond = args[0]; | ||
if (typeof cond !== 'function') { | ||
throw new Error('cmd.switch(function (when) { ... }) called without function as first argument'); | ||
} | ||
this.export = function () { | ||
var when = function (condition, result) { | ||
if (typeof result !== 'function') { | ||
throw new Error('when(condition, function () { ... }) called without function as second argument'); | ||
/** | ||
* Command: switch(function (when, val) { | ||
* when(val == 1, function () { return 'a'; }); | ||
* when(val == 2, function () { return 'b'; }); | ||
* when(val >= 3, function () { return 'c'; }); | ||
* })(1, 2, 3) === ['a', 'b', 'c'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.each = function (args, val) { | ||
var cond = args[0]; | ||
if (typeof cond !== 'function') { | ||
throw new Error('cmd.switch(function (when, x) { ... }) called without function as first argument'); | ||
} | ||
if (condition) { | ||
throw { | ||
name: 'ConditionMatched', | ||
result: result() | ||
}; | ||
} | ||
}; | ||
try { | ||
cond(when, val); | ||
} | ||
catch (e) { | ||
if (e.name === 'ConditionMatched') { | ||
return e.result; | ||
var when = function (condition, result) { | ||
if (condition) { | ||
throw { | ||
name: 'ConditionMatched', | ||
result: typeof result === 'function' ? result() : result | ||
}; | ||
} | ||
}; | ||
try { | ||
cond(when, val); | ||
} | ||
else { | ||
throw e; | ||
catch (e) { | ||
if (e.name === 'ConditionMatched') { | ||
return e.result; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].switch = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: upper('a') === ['A'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return ('' + val).toUpperCase(); | ||
this.export = function () { | ||
/** | ||
* Command: upper('a') === ['A'] | ||
* @author Nate Ferrero | ||
*/ | ||
this.args = []; | ||
this.each = function (args, val) { | ||
return ('' + val).toUpperCase(); | ||
}; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].upper = {} : this); |
(function () { | ||
'use strict'; | ||
/** | ||
* Command: view(#element) === ViewClass | ||
* new ViewClass(#element) to render | ||
* @author Nate Ferrero | ||
*/ | ||
var ViewClassPrototype = { | ||
update: function () { | ||
cmd.extend.apply(null, arguments)(this.scope); | ||
console.log(this.scope); | ||
this.render(); | ||
}, | ||
render: function () { | ||
while (this.node.lastChild) { | ||
this.node.removeChild(this.node.lastChild); | ||
this.export = function (cmd) { | ||
/** | ||
* Command: view(#element) === ViewClass | ||
* new ViewClass(#element) to render | ||
* @author Nate Ferrero | ||
*/ | ||
var ViewClassPrototype = { | ||
update: function () { | ||
cmd.extend.apply(null, arguments)(this.scope); | ||
console.log(this.scope); | ||
this.render(); | ||
}, | ||
render: function () { | ||
while (this.node.lastChild) { | ||
this.node.removeChild(this.node.lastChild); | ||
} | ||
this.node.appendChild(this.template.cloneNode(true)); | ||
} | ||
this.node.appendChild(this.template.cloneNode(true)); | ||
} | ||
}; | ||
}; | ||
this.args = []; | ||
this.all = function (args, vals) { | ||
var template = document.createDocumentFragment(); | ||
vals.forEach(function (val) { | ||
template.appendChild(val.content || val.cloneNode(true)); | ||
}); | ||
this.args = []; | ||
this.all = function (args, vals) { | ||
if (typeof document === 'undefined') { | ||
return | ||
} | ||
var template = document.createDocumentFragment(); | ||
vals.forEach(function (val) { | ||
template.appendChild(val.content || val.cloneNode(true)); | ||
}); | ||
var ViewClass = function (on) { | ||
this.on = on; | ||
this.template = document.importNode(template, true); | ||
this.node = document.createElement('view'); | ||
this.scope = {}; | ||
if (on) { | ||
on.appendChild(this.node); | ||
} | ||
this.render(); | ||
var ViewClass = function (on) { | ||
this.on = on; | ||
this.template = document.importNode(template, true); | ||
this.node = document.createElement('view'); | ||
this.scope = {}; | ||
if (on) { | ||
on.appendChild(this.node); | ||
} | ||
this.render(); | ||
}; | ||
ViewClass.prototype = ViewClassPrototype; | ||
return ViewClass; | ||
}; | ||
ViewClass.prototype = ViewClassPrototype; | ||
return ViewClass; | ||
}; | ||
}).call(typeof module === 'undefined' ? this['cmd:lib'].view = {} : this); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
61964
75
1409
0
194