Comparing version
@@ -1,74 +0,71 @@ | ||
(function() { | ||
var h, id, isArray, | ||
hasProp = {}.hasOwnProperty; | ||
var h, id, isArray, | ||
hasProp = {}.hasOwnProperty; | ||
isArray = Array.isArray; | ||
isArray = Array.isArray; | ||
h = /([^-])([A-Z])/g; | ||
h = /([^-])([A-Z])/g; | ||
id = 0; | ||
id = 0; | ||
module.exports = { | ||
getID: function() { | ||
return id++; | ||
}, | ||
noop: function() {}, | ||
identity: function(val) { | ||
return val; | ||
}, | ||
arrayize: function(obj) { | ||
if (isArray(obj)) { | ||
return obj; | ||
} else if (obj == null) { | ||
return []; | ||
module.exports = { | ||
getID: function() { | ||
return id++; | ||
}, | ||
noop: function() {}, | ||
identity: function(val) { | ||
return val; | ||
}, | ||
arrayize: function(obj) { | ||
if (isArray(obj)) { | ||
return obj; | ||
} else if (obj == null) { | ||
return []; | ||
} else { | ||
return [obj]; | ||
} | ||
}, | ||
isString: function(obj) { | ||
return typeof obj === "string" || obj instanceof String; | ||
}, | ||
isArray: isArray, | ||
isObject: function(obj) { | ||
return typeof obj === "object"; | ||
}, | ||
isFunction: function(obj) { | ||
return typeof obj === "function"; | ||
}, | ||
isElement: function(obj) { | ||
if (typeof HTMLElement === "object") { | ||
return obj instanceof HTMLElement; | ||
} else { | ||
return (obj != null) && (obj.nodeType != null) === 1 && typeof (obj.nodeName != null) === "string"; | ||
} | ||
}, | ||
camelize: function(str) { | ||
return str.replace(/-(\w)/g, function(_, c) { | ||
if (c) { | ||
return c.toUpperCase(); | ||
} else { | ||
return [obj]; | ||
return ''; | ||
} | ||
}, | ||
isString: function(obj) { | ||
return typeof obj === "string" || obj instanceof String; | ||
}, | ||
isArray: isArray, | ||
isObject: function(obj) { | ||
return typeof obj === "object"; | ||
}, | ||
isFunction: function(obj) { | ||
return typeof obj === "function"; | ||
}, | ||
isElement: function(obj) { | ||
if (typeof HTMLElement === "object") { | ||
return obj instanceof HTMLElement; | ||
} else { | ||
return (obj != null) && (obj.nodeType != null) === 1 && typeof (obj.nodeName != null) === "string"; | ||
} | ||
}, | ||
camelize: function(str) { | ||
return str.replace(/-(\w)/g, function(_, c) { | ||
if (c) { | ||
return c.toUpperCase(); | ||
} else { | ||
return ''; | ||
} | ||
}); | ||
}, | ||
capitalize: function(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}, | ||
hyphenate: function(str) { | ||
return str.replace(h, '$1-$2').toLowerCase(); | ||
}, | ||
clone: function(o) { | ||
var cln, k, v; | ||
cln = {}; | ||
for (k in o) { | ||
if (!hasProp.call(o, k)) continue; | ||
v = o[k]; | ||
cln[k] = v; | ||
} | ||
return cln; | ||
}); | ||
}, | ||
capitalize: function(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
}, | ||
hyphenate: function(str) { | ||
return str.replace(h, '$1-$2').toLowerCase(); | ||
}, | ||
clone: function(o) { | ||
var cln, k, v; | ||
cln = {}; | ||
for (k in o) { | ||
if (!hasProp.call(o, k)) continue; | ||
v = o[k]; | ||
cln[k] = v; | ||
} | ||
}; | ||
return cln; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,106 +0,103 @@ | ||
(function() { | ||
var arrayize; | ||
var arrayize; | ||
arrayize = require("./_helpers").arrayize; | ||
arrayize = require("./_helpers").arrayize; | ||
module.exports = { | ||
apply: function(obj, mixins, mergers) { | ||
var finisher, i, j, k, l, len, len1, len2, mergeFinisher, mergeInstructions, merger, mixin, sortedMixins, v; | ||
mergers = arrayize(mergers); | ||
mergeInstructions = {}; | ||
mergeFinisher = []; | ||
for (i = 0, len = mergers.length; i < len; i++) { | ||
merger = mergers[i]; | ||
mergeInstructions[merger.source] = merger.setup(obj.prototype); | ||
if (merger.finisher != null) { | ||
mergeFinisher.push(merger.finisher); | ||
} | ||
module.exports = { | ||
apply: function(obj, mixins, mergers) { | ||
var finisher, i, j, k, l, len, len1, len2, mergeFinisher, mergeInstructions, merger, mixin, sortedMixins, v; | ||
mergers = arrayize(mergers); | ||
mergeInstructions = {}; | ||
mergeFinisher = []; | ||
for (i = 0, len = mergers.length; i < len; i++) { | ||
merger = mergers[i]; | ||
mergeInstructions[merger.source] = merger.setup(obj.prototype); | ||
if (merger.finisher != null) { | ||
mergeFinisher.push(merger.finisher); | ||
} | ||
sortedMixins = mixins.sort(function(a, b) { | ||
return (b._prio || 0) - (a._prio || 0); | ||
}); | ||
for (j = 0, len1 = sortedMixins.length; j < len1; j++) { | ||
mixin = sortedMixins[j]; | ||
for (k in mergeInstructions) { | ||
v = mergeInstructions[k]; | ||
if (mixin[k] != null) { | ||
v.iterate(mixin[k]); | ||
} | ||
} | ||
} | ||
} | ||
sortedMixins = mixins.sort(function(a, b) { | ||
return (b._prio || 0) - (a._prio || 0); | ||
}); | ||
for (j = 0, len1 = sortedMixins.length; j < len1; j++) { | ||
mixin = sortedMixins[j]; | ||
for (k in mergeInstructions) { | ||
v = mergeInstructions[k]; | ||
if (typeof v.end === "function") { | ||
v.end(); | ||
if (mixin[k] != null) { | ||
v.iterate(mixin[k]); | ||
} | ||
} | ||
for (l = 0, len2 = mergeFinisher.length; l < len2; l++) { | ||
finisher = mergeFinisher[l]; | ||
finisher(obj); | ||
} | ||
for (k in mergeInstructions) { | ||
v = mergeInstructions[k]; | ||
if (typeof v.end === "function") { | ||
v.end(); | ||
} | ||
return obj; | ||
}, | ||
copy: function(merger) { | ||
if (merger.target == null) { | ||
merger.target = merger.source; | ||
} | ||
merger.setup = function(obj) { | ||
var k, name, ref, target, v; | ||
if (merger.target) { | ||
if (obj[name = merger.target] == null) { | ||
obj[name] = {}; | ||
} | ||
target = obj[merger.target]; | ||
} else { | ||
target = obj; | ||
if (obj[merger.source] != null) { | ||
ref = obj[merger.source]; | ||
for (k in ref) { | ||
v = ref[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
} | ||
for (l = 0, len2 = mergeFinisher.length; l < len2; l++) { | ||
finisher = mergeFinisher[l]; | ||
finisher(obj); | ||
} | ||
return obj; | ||
}, | ||
copy: function(merger) { | ||
if (merger.target == null) { | ||
merger.target = merger.source; | ||
} | ||
merger.setup = function(obj) { | ||
var k, name, ref, target, v; | ||
if (merger.target) { | ||
if (obj[name = merger.target] == null) { | ||
obj[name] = {}; | ||
} | ||
target = obj[merger.target]; | ||
} else { | ||
target = obj; | ||
if (obj[merger.source] != null) { | ||
ref = obj[merger.source]; | ||
for (k in ref) { | ||
v = ref[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
} | ||
} | ||
return { | ||
iterate: function(entry) { | ||
var results; | ||
results = []; | ||
for (k in entry) { | ||
v = entry[k]; | ||
results.push(target[k] != null ? target[k] : target[k] = v); | ||
} | ||
return results; | ||
} | ||
return { | ||
iterate: function(entry) { | ||
var results; | ||
results = []; | ||
for (k in entry) { | ||
v = entry[k]; | ||
results.push(target[k] != null ? target[k] : target[k] = v); | ||
} | ||
}; | ||
return results; | ||
} | ||
}; | ||
return merger; | ||
}, | ||
concat: function(merger) { | ||
if (merger.target == null) { | ||
merger.target = merger.source; | ||
} | ||
merger.setup = function(obj) { | ||
var tmp; | ||
tmp = []; | ||
return { | ||
iterate: function(entry) { | ||
return tmp = tmp.concat(arrayize(entry)); | ||
}, | ||
end: function() { | ||
if (merger.last) { | ||
return obj[merger.target] = tmp.concat(arrayize(obj[merger.source])); | ||
} else { | ||
return obj[merger.target] = arrayize(obj[merger.source]).concat(tmp); | ||
} | ||
}; | ||
return merger; | ||
}, | ||
concat: function(merger) { | ||
if (merger.target == null) { | ||
merger.target = merger.source; | ||
} | ||
merger.setup = function(obj) { | ||
var tmp; | ||
tmp = []; | ||
return { | ||
iterate: function(entry) { | ||
return tmp = tmp.concat(arrayize(entry)); | ||
}, | ||
end: function() { | ||
if (merger.last) { | ||
return obj[merger.target] = tmp.concat(arrayize(obj[merger.source])); | ||
} else { | ||
return obj[merger.target] = arrayize(obj[merger.source]).concat(tmp); | ||
} | ||
}; | ||
} | ||
}; | ||
return merger; | ||
} | ||
}; | ||
}; | ||
return merger; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,65 +0,62 @@ | ||
(function() { | ||
var called, fn; | ||
var called, fn; | ||
called = []; | ||
called = []; | ||
fn = function() { | ||
return called.push(arguments); | ||
}; | ||
fn = function() { | ||
return called.push(arguments); | ||
}; | ||
if ((typeof document !== "undefined" && document !== null) && (typeof window !== "undefined" && window !== null)) { | ||
document.addEventListener("DOMContentLoaded", function() { | ||
var args, cAF, i, j, len, len1, pre, rAF, ref, results, throttle; | ||
rAF = null; | ||
cAF = null; | ||
ref = ["", "moz", "webkit", "ms"]; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
pre = ref[i]; | ||
if (rAF == null) { | ||
rAF = window[pre + "requestAnimationFrame"]; | ||
if ((typeof document !== "undefined" && document !== null) && (typeof window !== "undefined" && window !== null)) { | ||
document.addEventListener("DOMContentLoaded", function() { | ||
var args, cAF, i, j, len, len1, pre, rAF, ref, results, throttle; | ||
rAF = null; | ||
cAF = null; | ||
ref = ["", "moz", "webkit", "ms"]; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
pre = ref[i]; | ||
if (rAF == null) { | ||
rAF = window[pre + "requestAnimationFrame"]; | ||
} | ||
if (cAF == null) { | ||
cAF = window[pre + "cancelAnimationFrame"]; | ||
} | ||
} | ||
if (rAF) { | ||
fn = function(el, event, cb) { | ||
var lastRequest; | ||
if (cb == null) { | ||
cb = event; | ||
event = el; | ||
el = window; | ||
} | ||
if (cAF == null) { | ||
cAF = window[pre + "cancelAnimationFrame"]; | ||
lastRequest = null; | ||
return el.addEventListener(event, function() { | ||
var args; | ||
args = arguments; | ||
cAF(lastRequest); | ||
return lastRequest = rAF(function() { | ||
return cb.apply(null, args); | ||
}); | ||
}); | ||
}; | ||
} else { | ||
throttle = require("lodash/throttle"); | ||
fn = function(el, event, cb) { | ||
if (cb == null) { | ||
cb = event; | ||
event = el; | ||
el = window; | ||
} | ||
} | ||
if (rAF) { | ||
fn = function(el, event, cb) { | ||
var lastRequest; | ||
if (cb == null) { | ||
cb = event; | ||
event = el; | ||
el = window; | ||
} | ||
lastRequest = null; | ||
return el.addEventListener(event, function() { | ||
var args; | ||
args = arguments; | ||
cAF(lastRequest); | ||
return lastRequest = rAF(function() { | ||
return cb.apply(null, args); | ||
}); | ||
}); | ||
}; | ||
} else { | ||
throttle = require("lodash/throttle"); | ||
fn = function(el, event, cb) { | ||
if (cb == null) { | ||
cb = event; | ||
event = el; | ||
el = window; | ||
} | ||
return el.addEventListener(event, throttle(cb, 66)); | ||
}; | ||
} | ||
results = []; | ||
for (j = 0, len1 = called.length; j < len1; j++) { | ||
args = called[j]; | ||
results.push(fn.apply(null, args)); | ||
} | ||
return results; | ||
}); | ||
} | ||
return el.addEventListener(event, throttle(cb, 66)); | ||
}; | ||
} | ||
results = []; | ||
for (j = 0, len1 = called.length; j < len1; j++) { | ||
args = called[j]; | ||
results.push(fn.apply(null, args)); | ||
} | ||
return results; | ||
}); | ||
} | ||
module.exports = fn; | ||
}).call(this); | ||
module.exports = fn; |
@@ -1,42 +0,37 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "#if", | ||
_v: 1, | ||
mixins: [require("./structure")], | ||
_attrLookup: { | ||
"if": { | ||
"#": function(el, path, mods) { | ||
return this.$structure.beforeInsert.push(function(structure) { | ||
var comment, index, parent, value; | ||
comment = document.createComment("#if"); | ||
parent = el.parentNode || this; | ||
if (parent === this) { | ||
value = this.$path.toValue({ | ||
path: path | ||
}).value; | ||
if (!value) { | ||
index = structure.indexOf(el); | ||
structure[index] = comment; | ||
module.exports = { | ||
_name: "#if", | ||
_v: 1, | ||
mixins: [require("./structure")], | ||
_attrLookup: { | ||
"if": { | ||
"#": function(el, path, mods) { | ||
return this.$structure.beforeInsert.push(function(structure) { | ||
var comment, index, parent, value; | ||
comment = document.createComment("#if"); | ||
parent = el.parentNode || this; | ||
if (parent === this) { | ||
value = this.$path.toValue({ | ||
path: path | ||
}).value; | ||
if (!value) { | ||
index = structure.indexOf(el); | ||
structure[index] = comment; | ||
} | ||
} | ||
return this.$watch.path({ | ||
path: path, | ||
cbs: function(value, oldVal) { | ||
if (value && comment.parentNode === parent) { | ||
return parent.replaceChild(el, comment); | ||
} else if (!value && el.parentNode === parent) { | ||
return parent.replaceChild(comment, el); | ||
} | ||
} | ||
return this.$watch.path({ | ||
path: path, | ||
cbs: function(value, oldVal) { | ||
if (value !== oldVal) { | ||
if (value && comment.parentNode === parent) { | ||
return parent.replaceChild(el, comment); | ||
} else if (!value && el.parentNode === parent) { | ||
return parent.replaceChild(comment, el); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,37 +0,32 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "#show", | ||
_v: 1, | ||
mixins: [require("./structure"), require("./style")], | ||
_attrLookup: { | ||
show: { | ||
"#": function(el, path, mods) { | ||
this.$style.set(el, { | ||
visibility: "hidden" | ||
}); | ||
return this.$watch.path({ | ||
path: path, | ||
cbs: function(value, oldVal) { | ||
var style; | ||
if (value !== oldVal) { | ||
style = { | ||
visibility: value ? null : "hidden" | ||
}; | ||
if (value && (mods != null ? mods.delay : void 0)) { | ||
return this.$nextTick(function() { | ||
return this.$style.set(el, style); | ||
}); | ||
} else { | ||
return this.$style.set(el, style); | ||
} | ||
} | ||
module.exports = { | ||
_name: "#show", | ||
_v: 1, | ||
mixins: [require("./structure"), require("./style")], | ||
_attrLookup: { | ||
show: { | ||
"#": function(el, path, mods) { | ||
this.$style.set(el, { | ||
visibility: "hidden" | ||
}); | ||
return this.$watch.path({ | ||
path: path, | ||
cbs: function(value, oldVal) { | ||
var style; | ||
style = { | ||
visibility: value ? null : "hidden" | ||
}; | ||
if (value && (mods != null ? mods.delay : void 0)) { | ||
return this.$nextTick(function() { | ||
return this.$style.set(el, style); | ||
}); | ||
} else { | ||
return this.$style.set(el, style); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,34 +0,31 @@ | ||
(function() { | ||
var isString; | ||
var isString; | ||
isString = require("./_helpers").isString; | ||
isString = require("./_helpers").isString; | ||
module.exports = { | ||
_name: "$setAttribute", | ||
_v: 1, | ||
methods: { | ||
$setAttribute: function(el, name, val) { | ||
if (isString(el)) { | ||
val = name; | ||
name = el; | ||
el = this; | ||
} | ||
if ((val != null) && val !== false && (isString(val) || !isNaN(val))) { | ||
if (val === true) { | ||
el.setAttribute(name, ""); | ||
} else { | ||
el.setAttribute(name, val); | ||
} | ||
module.exports = { | ||
_name: "$setAttribute", | ||
_v: 1, | ||
methods: { | ||
$setAttribute: function(el, name, val) { | ||
if (isString(el)) { | ||
val = name; | ||
name = el; | ||
el = this; | ||
} | ||
if ((val != null) && val !== false && (isString(val) || !isNaN(val))) { | ||
if (val === true) { | ||
el.setAttribute(name, ""); | ||
} else { | ||
el.removeAttribute(name); | ||
el.setAttribute(name, val); | ||
} | ||
return { | ||
then: this.$nextTick | ||
}; | ||
} else { | ||
el.removeAttribute(name); | ||
} | ||
return { | ||
then: this.$nextTick | ||
}; | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
285
lib/ceri.js
@@ -1,155 +0,152 @@ | ||
(function() { | ||
var isArray, isFunction, isObject, ref; | ||
var isArray, isFunction, isObject, ref; | ||
ref = require("./_helpers"), isObject = ref.isObject, isFunction = ref.isFunction, isArray = ref.isArray; | ||
ref = require("./_helpers"), isObject = ref.isObject, isFunction = ref.isFunction, isArray = ref.isArray; | ||
module.exports = function(ce) { | ||
var _merger, addReactionMerger, ceProto, flattenMixins, mergers; | ||
ceProto = ce.prototype; | ||
ceProto.$nextTick = function(cb) { | ||
return setTimeout(cb.bind(this), 0); | ||
module.exports = function(ce) { | ||
var _merger, addReactionMerger, ceProto, flattenMixins, mergers; | ||
ceProto = ce.prototype; | ||
ceProto.$nextTick = function(cb) { | ||
return setTimeout(cb.bind(this), 0); | ||
}; | ||
if (ceProto.mixins != null) { | ||
flattenMixins = function(mixins) { | ||
var addMixins, i, j, len, len1, mixin; | ||
addMixins = []; | ||
for (i = 0, len = mixins.length; i < len; i++) { | ||
mixin = mixins[i]; | ||
if (mixin.mixins != null) { | ||
addMixins = flattenMixins(mixin.mixins).concat(addMixins); | ||
} | ||
} | ||
for (j = 0, len1 = addMixins.length; j < len1; j++) { | ||
mixin = addMixins[j]; | ||
if (mixins.indexOf(mixin) === -1) { | ||
mixins.push(mixin); | ||
} | ||
} | ||
return mixins; | ||
}; | ||
if (ceProto.mixins != null) { | ||
flattenMixins = function(mixins) { | ||
var addMixins, i, j, len, len1, mixin; | ||
addMixins = []; | ||
for (i = 0, len = mixins.length; i < len; i++) { | ||
mixin = mixins[i]; | ||
if (mixin.mixins != null) { | ||
addMixins = flattenMixins(mixin.mixins).concat(addMixins); | ||
flattenMixins(ceProto.mixins); | ||
_merger = require("./_merger"); | ||
_merger.apply(ce, ceProto.mixins, _merger.concat({ | ||
source: "_mergers", | ||
target: "mergers" | ||
})); | ||
mergers = ceProto.mergers; | ||
delete ceProto.mergers; | ||
mergers.push(_merger.copy({ | ||
source: "methods", | ||
target: false | ||
})); | ||
mergers.push(_merger.concat({ | ||
source: "_rebind" | ||
})); | ||
addReactionMerger = function(name, short) { | ||
var merger; | ||
merger = _merger.concat({ | ||
source: name, | ||
target: short, | ||
last: true | ||
}); | ||
merger.finisher = function(obj) { | ||
return obj.prototype[name] = function() { | ||
var fn, i, len, ref1, results; | ||
ref1 = this[short]; | ||
results = []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
results.push(fn.apply(this, arguments)); | ||
} | ||
} | ||
for (j = 0, len1 = addMixins.length; j < len1; j++) { | ||
mixin = addMixins[j]; | ||
if (mixins.indexOf(mixin) === -1) { | ||
mixins.push(mixin); | ||
return results; | ||
}; | ||
}; | ||
return mergers.push(merger); | ||
}; | ||
addReactionMerger("disconnectedCallback", "_dCb"); | ||
addReactionMerger("attributeChangedCallback", "_acCb"); | ||
addReactionMerger("adoptedCallback", "_aCb"); | ||
mergers.push(_merger.concat({ | ||
source: "connectedCallback", | ||
target: "_cCb", | ||
last: true, | ||
finisher: function(obj) { | ||
return obj.prototype.connectedCallback = function() { | ||
var fn, i, len, ref1; | ||
ref1 = this._cCb; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
fn.apply(this, arguments); | ||
} | ||
} | ||
return mixins; | ||
}; | ||
flattenMixins(ceProto.mixins); | ||
_merger = require("./_merger"); | ||
_merger.apply(ce, ceProto.mixins, _merger.concat({ | ||
source: "_mergers", | ||
target: "mergers" | ||
})); | ||
mergers = ceProto.mergers; | ||
delete ceProto.mergers; | ||
mergers.push(_merger.copy({ | ||
source: "methods", | ||
target: false | ||
})); | ||
mergers.push(_merger.concat({ | ||
source: "_rebind" | ||
})); | ||
addReactionMerger = function(name, short) { | ||
var merger; | ||
merger = _merger.concat({ | ||
source: name, | ||
target: short, | ||
last: true | ||
}); | ||
merger.finisher = function(obj) { | ||
return obj.prototype[name] = function() { | ||
var fn, i, len, ref1, results; | ||
ref1 = this[short]; | ||
return this._isFirstConnect = false; | ||
}; | ||
} | ||
})); | ||
addReactionMerger("destroy", "_deCb"); | ||
mergers.push({ | ||
source: "created", | ||
setup: function(obj) { | ||
obj._crCb = [ | ||
function() { | ||
var i, k, k2, key, len, o1, o2, proto, ref1, results, v, v2; | ||
this._isCeri = true; | ||
this._isFirstConnect = true; | ||
proto = Object.getPrototypeOf(this); | ||
ref1 = this._rebind; | ||
results = []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
results.push(fn.apply(this, arguments)); | ||
key = ref1[i]; | ||
o1 = proto[key]; | ||
if(process.env.NODE_ENV!=='production' && !isObject(o1)){throw new Error('_rebind must target object: ' + key)}; | ||
o2 = {}; | ||
Object.defineProperty(this, key, { | ||
__proto__: null, | ||
value: o2 | ||
}); | ||
results.push((function() { | ||
var results1; | ||
results1 = []; | ||
for (k in o1) { | ||
v = o1[k]; | ||
if (isFunction(v)) { | ||
results1.push(o2[k] = v.bind(this)); | ||
} else if (isArray(v)) { | ||
results1.push(o2[k] = v.slice()); | ||
} else if (isObject(v) && (v != null)) { | ||
o2[k] = {}; | ||
results1.push((function() { | ||
var results2; | ||
results2 = []; | ||
for (k2 in v) { | ||
v2 = v[k2]; | ||
results2.push(o2[k2] = v2); | ||
} | ||
return results2; | ||
})()); | ||
} else { | ||
results1.push(o2[k] = v); | ||
} | ||
} | ||
return results1; | ||
}).call(this)); | ||
} | ||
return results; | ||
}; | ||
} | ||
]; | ||
return { | ||
iterate: function(entry) { | ||
return obj._crCb.push(entry); | ||
}, | ||
end: function() { | ||
if (obj.created != null) { | ||
return obj._crCb.push(obj.created); | ||
} | ||
} | ||
}; | ||
return mergers.push(merger); | ||
}; | ||
addReactionMerger("disconnectedCallback", "_dCb"); | ||
addReactionMerger("attributeChangedCallback", "_acCb"); | ||
addReactionMerger("adoptedCallback", "_aCb"); | ||
mergers.push(_merger.concat({ | ||
source: "connectedCallback", | ||
target: "_cCb", | ||
last: true, | ||
finisher: function(obj) { | ||
return obj.prototype.connectedCallback = function() { | ||
var fn, i, len, ref1; | ||
ref1 = this._cCb; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
fn.apply(this, arguments); | ||
} | ||
return this._isFirstConnect = false; | ||
}; | ||
} | ||
})); | ||
addReactionMerger("destroy", "_deCb"); | ||
mergers.push({ | ||
source: "created", | ||
setup: function(obj) { | ||
obj._crCb = [ | ||
function() { | ||
var i, k, k2, key, len, o1, o2, proto, ref1, results, v, v2; | ||
this._isCeri = true; | ||
this._isFirstConnect = true; | ||
proto = Object.getPrototypeOf(this); | ||
ref1 = this._rebind; | ||
results = []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
key = ref1[i]; | ||
o1 = proto[key]; | ||
if(process.env.NODE_ENV!=='production' && !isObject(o1)){throw new Error('_rebind must target object: ' + key)}; | ||
o2 = {}; | ||
Object.defineProperty(this, key, { | ||
__proto__: null, | ||
value: o2 | ||
}); | ||
results.push((function() { | ||
var results1; | ||
results1 = []; | ||
for (k in o1) { | ||
v = o1[k]; | ||
if (isFunction(v)) { | ||
results1.push(o2[k] = v.bind(this)); | ||
} else if (isArray(v)) { | ||
results1.push(o2[k] = v.slice()); | ||
} else if (isObject(v) && (v != null)) { | ||
o2[k] = {}; | ||
results1.push((function() { | ||
var results2; | ||
results2 = []; | ||
for (k2 in v) { | ||
v2 = v[k2]; | ||
results2.push(o2[k2] = v2); | ||
} | ||
return results2; | ||
})()); | ||
} else { | ||
results1.push(o2[k] = v); | ||
} | ||
} | ||
return results1; | ||
}).call(this)); | ||
} | ||
return results; | ||
} | ||
]; | ||
return { | ||
iterate: function(entry) { | ||
return obj._crCb.push(entry); | ||
}, | ||
end: function() { | ||
if (obj.created != null) { | ||
return obj._crCb.push(obj.created); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
_merger.apply(ce, ceProto.mixins, mergers); | ||
} | ||
return ce; | ||
}; | ||
} | ||
}); | ||
_merger.apply(ce, ceProto.mixins, mergers); | ||
} | ||
return ce; | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,47 +0,44 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "class", | ||
_v: 1, | ||
_rebind: "$class", | ||
methods: { | ||
$class: { | ||
strToObj: function(str) { | ||
var cls, i, len, ref, result; | ||
result = {}; | ||
if (str != null) { | ||
ref = str.split(" "); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
cls = ref[i]; | ||
result[cls] = true; | ||
} | ||
module.exports = { | ||
_name: "class", | ||
_v: 1, | ||
_rebind: "$class", | ||
methods: { | ||
$class: { | ||
strToObj: function(str) { | ||
var cls, i, len, ref, result; | ||
result = {}; | ||
if (str != null) { | ||
ref = str.split(" "); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
cls = ref[i]; | ||
result[cls] = true; | ||
} | ||
return result; | ||
}, | ||
objToStr: function(obj) { | ||
var k, result, v; | ||
result = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
if (v) { | ||
result.push(k); | ||
} | ||
} | ||
return result; | ||
}, | ||
objToStr: function(obj) { | ||
var k, result, v; | ||
result = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
if (v) { | ||
result.push(k); | ||
} | ||
return result.join(" "); | ||
}, | ||
setStr: function(el, str) { | ||
return el.className = str; | ||
}, | ||
set: function(el, obj) { | ||
if (obj == null) { | ||
obj = el; | ||
el = this; | ||
} | ||
return this.$class.setStr(el, this.$class.objToStr(obj)); | ||
} | ||
return result.join(" "); | ||
}, | ||
setStr: function(el, str) { | ||
return el.className = str; | ||
}, | ||
set: function(el, obj) { | ||
if (obj == null) { | ||
obj = el; | ||
el = this; | ||
} | ||
return this.$class.setStr(el, this.$class.objToStr(obj)); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,34 +0,31 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "classes", | ||
_v: 1, | ||
_prio: 700, | ||
_mergers: require("./_merger").copy({ | ||
source: "classes" | ||
}), | ||
mixins: [require("./class"), require("./combined")], | ||
created: function() { | ||
return this.$combined({ | ||
path: "classes", | ||
value: this.classes, | ||
parseProp: this.$class.strToObj, | ||
cbFactory: function(name) { | ||
var el; | ||
if (name === "this") { | ||
el = this; | ||
} else { | ||
el = this[name]; | ||
module.exports = { | ||
_name: "classes", | ||
_v: 1, | ||
_prio: 700, | ||
_mergers: require("./_merger").copy({ | ||
source: "classes" | ||
}), | ||
mixins: [require("./class"), require("./combined")], | ||
created: function() { | ||
return this.$combined({ | ||
path: "classes", | ||
value: this.classes, | ||
parseProp: this.$class.strToObj, | ||
cbFactory: function(name) { | ||
var el; | ||
if (name === "this") { | ||
el = this; | ||
} else { | ||
el = this[name]; | ||
} | ||
return [ | ||
function(val) { | ||
return this.$class.set(el, val); | ||
} | ||
return [ | ||
function(val) { | ||
return this.$class.set(el, val); | ||
} | ||
]; | ||
} | ||
}); | ||
} | ||
}; | ||
]; | ||
} | ||
}); | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,109 +0,106 @@ | ||
(function() { | ||
var identity, noop, ref; | ||
var identity, noop, ref; | ||
ref = require("./_helpers"), identity = ref.identity, noop = ref.noop; | ||
ref = require("./_helpers"), identity = ref.identity, noop = ref.noop; | ||
module.exports = { | ||
_name: "combined", | ||
_v: 1, | ||
mixins: [require("./watch"), require("./computed")], | ||
methods: { | ||
$combined: function(o) { | ||
var combinedParent; | ||
this.$path.toNameAndParent(o); | ||
if (!o.parent.hasOwnProperty(o.name)) { | ||
Object.defineProperty(o.parent, o.name, { | ||
__proto__: null, | ||
value: {} | ||
}); | ||
} | ||
combinedParent = o.parent[o.name]; | ||
return Object.keys(o.value).forEach((function(_this) { | ||
return function(name) { | ||
var combined, computed, createObj, data, deferred, makeHiddenName, v; | ||
v = o.value[name]; | ||
makeHiddenName = function(name2) { | ||
return "__" + name + "_" + name2; | ||
}; | ||
createObj = function(obj) { | ||
obj.path = o.path + "." + obj.name; | ||
obj.parent = combinedParent; | ||
return obj; | ||
}; | ||
if (v.computed != null) { | ||
computed = makeHiddenName("computed"); | ||
_this.$computed.init(createObj({ | ||
name: computed, | ||
get: v.computed | ||
})); | ||
} else { | ||
computed = null; | ||
} | ||
if (v.data != null) { | ||
data = name; | ||
_this.$watch.path(createObj({ | ||
name: data, | ||
value: v.data.call(_this) | ||
})); | ||
} else { | ||
data = null; | ||
} | ||
combined = makeHiddenName("combined"); | ||
deferred = function() { | ||
var getterFactory; | ||
getterFactory = function(parent, combined, prop, computed, data, normalize, parseProp) { | ||
var getter; | ||
getter = function() { | ||
var k, obj, propVal, ref1, ref2; | ||
if (prop && ((propVal = this[prop]) != null)) { | ||
obj = normalize(parseProp(propVal)); | ||
} else { | ||
obj = {}; | ||
} | ||
if (computed) { | ||
ref1 = normalize(parent[computed]); | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
module.exports = { | ||
_name: "combined", | ||
_v: 1, | ||
mixins: [require("./watch"), require("./computed")], | ||
methods: { | ||
$combined: function(o) { | ||
var combinedParent; | ||
this.$path.toNameAndParent(o); | ||
if (!o.parent.hasOwnProperty(o.name)) { | ||
Object.defineProperty(o.parent, o.name, { | ||
__proto__: null, | ||
value: {} | ||
}); | ||
} | ||
combinedParent = o.parent[o.name]; | ||
return Object.keys(o.value).forEach((function(_this) { | ||
return function(name) { | ||
var combined, computed, createObj, data, deferred, makeHiddenName, v; | ||
v = o.value[name]; | ||
makeHiddenName = function(name2) { | ||
return "__" + name + "_" + name2; | ||
}; | ||
createObj = function(obj) { | ||
obj.path = o.path + "." + obj.name; | ||
obj.parent = combinedParent; | ||
return obj; | ||
}; | ||
if (v.computed != null) { | ||
computed = makeHiddenName("computed"); | ||
_this.$computed.init(createObj({ | ||
name: computed, | ||
get: v.computed | ||
})); | ||
} else { | ||
computed = null; | ||
} | ||
if (v.data != null) { | ||
data = name; | ||
_this.$watch.path(createObj({ | ||
name: data, | ||
value: v.data.call(_this) | ||
})); | ||
} else { | ||
data = null; | ||
} | ||
combined = makeHiddenName("combined"); | ||
deferred = function() { | ||
var getterFactory; | ||
getterFactory = function(parent, combined, prop, computed, data, normalize, parseProp) { | ||
var getter; | ||
getter = function() { | ||
var k, obj, propVal, ref1, ref2; | ||
if (prop && ((propVal = this[prop]) != null)) { | ||
obj = normalize(parseProp(propVal)); | ||
} else { | ||
obj = {}; | ||
} | ||
if (computed) { | ||
ref1 = normalize(parent[computed]); | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
} | ||
if (data) { | ||
ref2 = normalize(parent[data]); | ||
for (k in ref2) { | ||
v = ref2[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
} | ||
if (data) { | ||
ref2 = normalize(parent[data]); | ||
for (k in ref2) { | ||
v = ref2[k]; | ||
if (obj[k] == null) { | ||
obj[k] = v; | ||
} | ||
} | ||
return obj; | ||
}; | ||
return getter.bind(this); | ||
} | ||
return obj; | ||
}; | ||
return this.$computed.init(createObj({ | ||
name: combined, | ||
cbs: o.cbFactory.call(this, name), | ||
get: getterFactory.call(this, combinedParent, combined, v.prop, computed, data, o.normalize || identity, o.parseProp || identity) | ||
})); | ||
return getter.bind(this); | ||
}; | ||
if (_this.$computed.__deferredInits) { | ||
Object.defineProperty(combinedParent, combined, { | ||
configurable: true, | ||
set: noop, | ||
get: noop | ||
}); | ||
return _this.$computed.__deferredInits.push(deferred); | ||
} else { | ||
return deferred.call(_this); | ||
} | ||
return this.$computed.init(createObj({ | ||
name: combined, | ||
cbs: o.cbFactory.call(this, name), | ||
get: getterFactory.call(this, combinedParent, combined, v.prop, computed, data, o.normalize || identity, o.parseProp || identity) | ||
})); | ||
}; | ||
})(this)); | ||
} | ||
if (_this.$computed.__deferredInits) { | ||
Object.defineProperty(combinedParent, combined, { | ||
configurable: true, | ||
set: noop, | ||
get: noop | ||
}); | ||
return _this.$computed.__deferredInits.push(deferred); | ||
} else { | ||
return deferred.call(_this); | ||
} | ||
}; | ||
})(this)); | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,168 +0,165 @@ | ||
(function() { | ||
var clone, getID, isFunction, isObject, noop, ref; | ||
var clone, getID, isFunction, isObject, noop, ref; | ||
ref = require("./_helpers"), noop = ref.noop, isObject = ref.isObject, isFunction = ref.isFunction, clone = ref.clone, getID = ref.getID; | ||
ref = require("./_helpers"), noop = ref.noop, isObject = ref.isObject, isFunction = ref.isFunction, clone = ref.clone, getID = ref.getID; | ||
window.__ceriDeps = null; | ||
window.__ceriDeps = null; | ||
module.exports = { | ||
_name: "computed", | ||
_prio: 900, | ||
_v: 1, | ||
_mergers: require("./_merger").copy({ | ||
source: "computed" | ||
}), | ||
_rebind: "$computed", | ||
mixins: [require("./watch")], | ||
methods: { | ||
$computed: { | ||
__deferredInits: [], | ||
init: function(o) { | ||
var deferred; | ||
this.$watch.parse(o); | ||
o = this.$watch.init(o); | ||
if (o) { | ||
o.id = getID(); | ||
o.deps = function(id) { | ||
o.deps[id] = true; | ||
return o; | ||
}; | ||
o.cDeps = []; | ||
o.notify = function() { | ||
var c, cb, i, j, len, len1, newVal, oldVal, ref1, ref2, results; | ||
o.dirty = true; | ||
if (o.cbs.length > 0) { | ||
oldVal = o.value; | ||
newVal = o.parent[o.name]; | ||
ref1 = o.cbs; | ||
module.exports = { | ||
_name: "computed", | ||
_prio: 900, | ||
_v: 1, | ||
_mergers: require("./_merger").copy({ | ||
source: "computed" | ||
}), | ||
_rebind: "$computed", | ||
mixins: [require("./watch")], | ||
methods: { | ||
$computed: { | ||
__deferredInits: [], | ||
init: function(o) { | ||
var deferred; | ||
this.$watch.parse(o); | ||
o = this.$watch.init(o); | ||
if (o) { | ||
o.id = getID(); | ||
o.deps = function(id) { | ||
o.deps[id] = true; | ||
return o; | ||
}; | ||
o.cDeps = []; | ||
o.notify = function() { | ||
var c, cb, i, j, len, len1, newVal, oldVal, ref1, ref2, results; | ||
o.dirty = true; | ||
if (o.cbs.length > 0) { | ||
oldVal = o.value; | ||
newVal = o.parent[o.name]; | ||
ref1 = o.cbs; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
cb = ref1[i]; | ||
cb(newVal, oldVal); | ||
} | ||
} | ||
ref2 = o.cDeps; | ||
results = []; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
c = ref2[j]; | ||
if (!c.dirty) { | ||
results.push(c.notify()); | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
return results; | ||
}; | ||
if (o.set != null) { | ||
o.set = o.set.bind(this); | ||
} else { | ||
o.set = noop; | ||
} | ||
o.get = o.get.bind(this); | ||
o.oldValue = null; | ||
o.getter = function() { | ||
var c, i, len, ref1, tmp; | ||
if (o.dirty) { | ||
o.dirty = false; | ||
tmp = window.__ceriDeps; | ||
window.__ceriDeps = o.deps; | ||
o.oldValue = o.value; | ||
o.value = o.get(); | ||
this.$watch.processNewValue(o); | ||
window.__ceriDeps = tmp; | ||
if (!isObject(o.value) && o.oldValue !== o.value) { | ||
ref1 = o.cDeps; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
cb = ref1[i]; | ||
cb(newVal, oldVal); | ||
c = ref1[i]; | ||
if (!c.dirty && (o.deps[c.id] != null)) { | ||
c.notify(); | ||
} | ||
} | ||
} | ||
ref2 = o.cDeps; | ||
results = []; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
c = ref2[j]; | ||
if (!c.dirty) { | ||
results.push(c.notify()); | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
return results; | ||
}; | ||
if (o.set != null) { | ||
o.set = o.set.bind(this); | ||
} | ||
if ((window.__ceriDeps != null) && (window.__ceriDeps[o.id] == null)) { | ||
o.cDeps.push(window.__ceriDeps(o.id)); | ||
} | ||
return o.value; | ||
}; | ||
o.getter = o.getter.bind(this); | ||
deferred = function() { | ||
o.dirty = true; | ||
Object.defineProperty(o.parent, o.name, { | ||
get: o.getter, | ||
set: o.set | ||
}); | ||
if (o.cbs.length > 0) { | ||
return this.$nextTick(o.notify); | ||
} else { | ||
o.set = noop; | ||
} | ||
o.get = o.get.bind(this); | ||
o.oldValue = null; | ||
o.getter = function() { | ||
var c, i, len, ref1, tmp; | ||
if (o.dirty) { | ||
o.dirty = false; | ||
tmp = window.__ceriDeps; | ||
window.__ceriDeps = o.deps; | ||
o.oldValue = o.value; | ||
o.value = o.get(); | ||
this.$watch.processNewValue(o); | ||
window.__ceriDeps = tmp; | ||
if (!isObject(o.value) && o.oldValue !== o.value) { | ||
ref1 = o.cDeps; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
c = ref1[i]; | ||
if (!c.dirty && (o.deps[c.id] != null)) { | ||
c.notify(); | ||
} | ||
return this.$nextTick(function() { | ||
var i, k, len, ref1, results; | ||
ref1 = Object.keys(this.$watch.__w); | ||
results = []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
k = ref1[i]; | ||
if (k.indexOf(o.path) > -1 && k !== o.path) { | ||
o.parent[o.name]; | ||
break; | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
} | ||
if ((window.__ceriDeps != null) && (window.__ceriDeps[o.id] == null)) { | ||
o.cDeps.push(window.__ceriDeps(o.id)); | ||
} | ||
return o.value; | ||
}; | ||
o.getter = o.getter.bind(this); | ||
deferred = function() { | ||
o.dirty = true; | ||
Object.defineProperty(o.parent, o.name, { | ||
get: o.getter, | ||
set: o.set | ||
return results; | ||
}); | ||
if (o.cbs.length > 0) { | ||
return this.$nextTick(o.notify); | ||
} else { | ||
return this.$nextTick(function() { | ||
var i, k, len, ref1, results; | ||
ref1 = Object.keys(this.$watch.__w); | ||
results = []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
k = ref1[i]; | ||
if (k.indexOf(o.path) > -1 && k !== o.path) { | ||
o.parent[o.name]; | ||
break; | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
return results; | ||
}); | ||
} | ||
}; | ||
if (this.$computed.__deferredInits && !o.noWait) { | ||
return this.$computed.__deferredInits.push(deferred); | ||
} else { | ||
return deferred.call(this); | ||
} | ||
}; | ||
if (this.$computed.__deferredInits && !o.noWait) { | ||
return this.$computed.__deferredInits.push(deferred); | ||
} else { | ||
return deferred.call(this); | ||
} | ||
}, | ||
getNotifyCb: function(o) { | ||
if(process.env.NODE_ENV!=='production' && o.path == null){console.warn('getNotifyCb requires a path')}; | ||
if (((o = this.$watch.getObj(o)) != null) && (o.notify != null)) { | ||
return o.notify; | ||
} | ||
if(process.env.NODE_ENV!=='production' && true){console.warn('couldn\'t get notify cb for computed ' + o.path)}; | ||
return noop; | ||
} | ||
}, | ||
getNotifyCb: function(o) { | ||
if(process.env.NODE_ENV!=='production' && o.path == null){console.warn('getNotifyCb requires a path')}; | ||
if (((o = this.$watch.getObj(o)) != null) && (o.notify != null)) { | ||
return o.notify; | ||
} | ||
if(process.env.NODE_ENV!=='production' && true){console.warn('couldn\'t get notify cb for computed ' + o.path)}; | ||
return noop; | ||
} | ||
}, | ||
created: function() { | ||
var k, ref1, results, v; | ||
ref1 = this.computed; | ||
} | ||
}, | ||
created: function() { | ||
var k, ref1, results, v; | ||
ref1 = this.computed; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (isObject(v)) { | ||
v = clone(v); | ||
} else { | ||
v = { | ||
get: v | ||
}; | ||
} | ||
v.parent = this; | ||
v.name = k; | ||
v.path = k; | ||
results.push(this.$computed.init(v)); | ||
} | ||
return results; | ||
}, | ||
connectedCallback: function() { | ||
return this.$nextTick(function() { | ||
var arr, deferred, i, len, results; | ||
arr = this.$computed.__deferredInits; | ||
this.$computed.__deferredInits = false; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (isObject(v)) { | ||
v = clone(v); | ||
} else { | ||
v = { | ||
get: v | ||
}; | ||
} | ||
v.parent = this; | ||
v.name = k; | ||
v.path = k; | ||
results.push(this.$computed.init(v)); | ||
for (i = 0, len = arr.length; i < len; i++) { | ||
deferred = arr[i]; | ||
results.push(deferred.call(this)); | ||
} | ||
return results; | ||
}, | ||
connectedCallback: function() { | ||
return this.$nextTick(function() { | ||
var arr, deferred, i, len, results; | ||
arr = this.$computed.__deferredInits; | ||
this.$computed.__deferredInits = false; | ||
results = []; | ||
for (i = 0, len = arr.length; i < len; i++) { | ||
deferred = arr[i]; | ||
results.push(deferred.call(this)); | ||
} | ||
return results; | ||
}); | ||
} | ||
}; | ||
}); | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,54 +0,51 @@ | ||
(function() { | ||
var arrayize, isString, ref; | ||
var arrayize, isString, ref; | ||
ref = require("./_helpers"), isString = ref.isString, arrayize = ref.arrayize; | ||
ref = require("./_helpers"), isString = ref.isString, arrayize = ref.arrayize; | ||
module.exports = { | ||
_name: "events", | ||
_v: 1, | ||
_prio: 900, | ||
_mergers: require("./_merger").copy({ | ||
source: "events" | ||
}), | ||
methods: { | ||
"$emit": function(el, name, options) { | ||
var evt; | ||
if (isString(el)) { | ||
options = name; | ||
name = el; | ||
el = this; | ||
} | ||
evt = document.createEvent('CustomEvent'); | ||
evt.initCustomEvent(name, false, false, options); | ||
return el.dispatchEvent(evt); | ||
module.exports = { | ||
_name: "events", | ||
_v: 1, | ||
_prio: 900, | ||
_mergers: require("./_merger").copy({ | ||
source: "events" | ||
}), | ||
methods: { | ||
"$emit": function(el, name, options) { | ||
var evt; | ||
if (isString(el)) { | ||
options = name; | ||
name = el; | ||
el = this; | ||
} | ||
}, | ||
connectedCallback: function() { | ||
var fn, k, ref1, results, v; | ||
if (this._isFirstConnect) { | ||
ref1 = this.events; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
results.push((function() { | ||
var i, len, ref2, results1; | ||
ref2 = arrayize(v); | ||
results1 = []; | ||
for (i = 0, len = ref2.length; i < len; i++) { | ||
fn = ref2[i]; | ||
if (isString(fn)) { | ||
fn = this[fn]; | ||
} | ||
results1.push(this.addEventListener(k, fn)); | ||
evt = document.createEvent('CustomEvent'); | ||
evt.initCustomEvent(name, false, false, options); | ||
return el.dispatchEvent(evt); | ||
} | ||
}, | ||
connectedCallback: function() { | ||
var fn, k, ref1, results, v; | ||
if (this._isFirstConnect) { | ||
ref1 = this.events; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
results.push((function() { | ||
var i, len, ref2, results1; | ||
ref2 = arrayize(v); | ||
results1 = []; | ||
for (i = 0, len = ref2.length; i < len; i++) { | ||
fn = ref2[i]; | ||
if (isString(fn)) { | ||
fn = this[fn]; | ||
} | ||
return results1; | ||
}).call(this)); | ||
} | ||
return results; | ||
results1.push(this.addEventListener(k, fn)); | ||
} | ||
return results1; | ||
}).call(this)); | ||
} | ||
return results; | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,55 +0,52 @@ | ||
(function() { | ||
var splittedToObjects; | ||
var splittedToObjects; | ||
splittedToObjects = function(splitted, obj) { | ||
return splitted.reduce((function(arr, name, i) { | ||
arr.push(arr[i][name]); | ||
return arr; | ||
}), [obj]); | ||
}; | ||
splittedToObjects = function(splitted, obj) { | ||
return splitted.reduce((function(arr, name, i) { | ||
arr.push(arr[i][name]); | ||
return arr; | ||
}), [obj]); | ||
}; | ||
module.exports = { | ||
_name: "path", | ||
_v: 1, | ||
_rebind: "$path", | ||
methods: { | ||
$path: { | ||
toValue: function(o) { | ||
if (o.value == null) { | ||
if (o.parent && o.name) { | ||
o.value = o.parent[o.name]; | ||
} else { | ||
if (o.obj == null) { | ||
o.obj = this; | ||
} | ||
o.value = splittedToObjects(o.path.split("."), o.obj).pop(); | ||
module.exports = { | ||
_name: "path", | ||
_v: 1, | ||
_rebind: "$path", | ||
methods: { | ||
$path: { | ||
toValue: function(o) { | ||
if (o.value == null) { | ||
if (o.parent && o.name) { | ||
o.value = o.parent[o.name]; | ||
} else { | ||
if (o.obj == null) { | ||
o.obj = this; | ||
} | ||
o.value = splittedToObjects(o.path.split("."), o.obj).pop(); | ||
} | ||
} | ||
return o; | ||
}, | ||
setValue: function(o) { | ||
if (o.value != null) { | ||
this.$path.toNameAndParent(o); | ||
return o.parent[o.name] = o.value; | ||
} | ||
}, | ||
toNameAndParent: function(o) { | ||
var splitted; | ||
if (o.name && o.parent) { | ||
return o; | ||
}, | ||
setValue: function(o) { | ||
if (o.value != null) { | ||
this.$path.toNameAndParent(o); | ||
return o.parent[o.name] = o.value; | ||
} | ||
}, | ||
toNameAndParent: function(o) { | ||
var splitted; | ||
if (o.name && o.parent) { | ||
return o; | ||
} | ||
splitted = o.path.split("."); | ||
if (o.obj == null) { | ||
o.obj = this; | ||
} | ||
o.name = splitted.pop(); | ||
o.parent = splittedToObjects(splitted, o.obj).pop(); | ||
return o; | ||
} | ||
splitted = o.path.split("."); | ||
if (o.obj == null) { | ||
o.obj = this; | ||
} | ||
o.name = splitted.pop(); | ||
o.parent = splittedToObjects(splitted, o.obj).pop(); | ||
return o; | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
193
lib/props.js
@@ -1,110 +0,107 @@ | ||
(function() { | ||
var arrayize, camelize, hyphenate, ref; | ||
var arrayize, camelize, hyphenate, ref; | ||
ref = require("./_helpers"), arrayize = ref.arrayize, hyphenate = ref.hyphenate, camelize = ref.camelize; | ||
ref = require("./_helpers"), arrayize = ref.arrayize, hyphenate = ref.hyphenate, camelize = ref.camelize; | ||
module.exports = { | ||
_name: "props", | ||
_v: 1, | ||
_prio: 900, | ||
_mergers: require("./_merger").copy({ | ||
source: "props", | ||
finisher: function(obj) { | ||
var arr, hyphenated, k, ref1, v; | ||
arr = arrayize(obj.prototype.observedAttributes); | ||
ref1 = obj.prototype.props; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
hyphenated = hyphenate(k); | ||
if (!(arr.indexOf(hyphenated) > -1)) { | ||
arr.push(hyphenated); | ||
} | ||
module.exports = { | ||
_name: "props", | ||
_v: 1, | ||
_prio: 900, | ||
_mergers: require("./_merger").copy({ | ||
source: "props", | ||
finisher: function(obj) { | ||
var arr, hyphenated, k, ref1, v; | ||
arr = arrayize(obj.prototype.observedAttributes); | ||
ref1 = obj.prototype.props; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
hyphenated = hyphenate(k); | ||
if (!(arr.indexOf(hyphenated) > -1)) { | ||
arr.push(hyphenated); | ||
} | ||
return Object.defineProperty(obj, "observedAttributes", { | ||
value: arr | ||
}); | ||
} | ||
}), | ||
mixins: [require("./watch"), require("./$setAttribute")], | ||
attributeChangedCallback: function(name, oldVal, newVal) { | ||
var camelized, prop, val; | ||
camelized = camelize(name); | ||
if ((prop = this.props[camelized]) == null) { | ||
return; | ||
return Object.defineProperty(obj, "observedAttributes", { | ||
value: arr | ||
}); | ||
} | ||
}), | ||
mixins: [require("./watch"), require("./$setAttribute")], | ||
attributeChangedCallback: function(name, oldVal, newVal) { | ||
var camelized, prop, val; | ||
camelized = camelize(name); | ||
if ((prop = this.props[camelized]) == null) { | ||
return; | ||
} | ||
if (prop.type === Number && (newVal != null)) { | ||
val = Number(newVal); | ||
} else if (prop.type === Boolean) { | ||
val = newVal != null; | ||
} else { | ||
val = newVal; | ||
} | ||
if (prop.name != null) { | ||
camelized = prop.name; | ||
} | ||
if (this[camelized] !== val) { | ||
return this[camelized] = val; | ||
} | ||
}, | ||
created: function() { | ||
var k, name, ref1, results, v; | ||
if (this.props == null) { | ||
this.props = {}; | ||
} | ||
ref1 = this.props; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (v.type == null) { | ||
this.props[k] = { | ||
type: v | ||
}; | ||
v = this.props[k]; | ||
} | ||
if (prop.type === Number && (newVal != null)) { | ||
val = Number(newVal); | ||
} else if (prop.type === Boolean) { | ||
val = newVal != null; | ||
if (v.type === Boolean && (v["default"] == null)) { | ||
v["default"] = false; | ||
} | ||
if (v.name) { | ||
name = v.name; | ||
} else { | ||
val = newVal; | ||
name = k; | ||
} | ||
if (prop.name != null) { | ||
camelized = prop.name; | ||
} | ||
if (this[camelized] !== val) { | ||
return this[camelized] = val; | ||
} | ||
}, | ||
created: function() { | ||
var k, name, ref1, results, v; | ||
if (this.props == null) { | ||
this.props = {}; | ||
} | ||
ref1 = this.props; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (v.type == null) { | ||
this.props[k] = { | ||
type: v | ||
}; | ||
v = this.props[k]; | ||
} | ||
if (v.type === Boolean && (v["default"] == null)) { | ||
v["default"] = false; | ||
} | ||
if (v.name) { | ||
name = v.name; | ||
} else { | ||
name = k; | ||
} | ||
results.push(this.$watch.path({ | ||
parent: this, | ||
name: name, | ||
path: name, | ||
initial: false, | ||
value: this[name], | ||
cbs: [this.$setAttribute.bind(this, this, hyphenate(k))] | ||
})); | ||
} | ||
return results; | ||
}, | ||
connectedCallback: function() { | ||
if (this._isFirstConnect) { | ||
return this.$nextTick(function() { | ||
var k, name, ref1, results, v; | ||
ref1 = this.props; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (v["default"] != null) { | ||
if (v.name) { | ||
name = v.name; | ||
} else { | ||
name = k; | ||
} | ||
results.push(this[name] != null ? this[name] : this[name] = v["default"]); | ||
results.push(this.$watch.path({ | ||
parent: this, | ||
name: name, | ||
path: name, | ||
initial: false, | ||
value: this[name], | ||
cbs: [this.$setAttribute.bind(this, this, hyphenate(k))] | ||
})); | ||
} | ||
return results; | ||
}, | ||
connectedCallback: function() { | ||
if (this._isFirstConnect) { | ||
return this.$nextTick(function() { | ||
var k, name, ref1, results, v; | ||
ref1 = this.props; | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (v["default"] != null) { | ||
if (v.name) { | ||
name = v.name; | ||
} else { | ||
results.push(void 0); | ||
name = k; | ||
} | ||
results.push(this[name] != null ? this[name] : this[name] = v["default"]); | ||
} else { | ||
results.push(void 0); | ||
} | ||
return results; | ||
}); | ||
} | ||
} | ||
return results; | ||
}); | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,214 +0,211 @@ | ||
(function() { | ||
var arrayize, camelize, isElement, isString, ref, | ||
slice = [].slice; | ||
var arrayize, camelize, isElement, isString, ref, | ||
slice = [].slice; | ||
ref = require("./_helpers"), isElement = ref.isElement, isString = ref.isString, arrayize = ref.arrayize, camelize = ref.camelize; | ||
ref = require("./_helpers"), isElement = ref.isElement, isString = ref.isString, arrayize = ref.arrayize, camelize = ref.camelize; | ||
module.exports = { | ||
_name: "structure", | ||
_v: 1, | ||
_prio: 800, | ||
_mergers: [ | ||
require("./_merger").copy({ | ||
source: "_elLookup" | ||
}), require("./_merger").copy({ | ||
source: "_attrLookup" | ||
}) | ||
], | ||
_rebind: "$structure", | ||
mixins: [require("./path"), require("./watch"), require("./$setAttribute")], | ||
_attrLookup: { | ||
text: { | ||
":": function(el, val) { | ||
return this.$watch.path({ | ||
path: val, | ||
cbs: function(val) { | ||
return el.textContent = val; | ||
} | ||
}); | ||
}, | ||
"#": function(el, val) { | ||
return el.textContent = val; | ||
} | ||
module.exports = { | ||
_name: "structure", | ||
_v: 1, | ||
_prio: 800, | ||
_mergers: [ | ||
require("./_merger").copy({ | ||
source: "_elLookup" | ||
}), require("./_merger").copy({ | ||
source: "_attrLookup" | ||
}) | ||
], | ||
_rebind: "$structure", | ||
mixins: [require("./path"), require("./watch"), require("./$setAttribute")], | ||
_attrLookup: { | ||
text: { | ||
":": function(el, val) { | ||
return this.$watch.path({ | ||
path: val, | ||
cbs: function(val) { | ||
return el.textContent = val; | ||
} | ||
}); | ||
}, | ||
ref: { | ||
"#": function(el, val) { | ||
return this[val] = el; | ||
} | ||
"#": function(el, val) { | ||
return el.textContent = val; | ||
} | ||
}, | ||
methods: { | ||
"$structure": { | ||
beforeInsert: [], | ||
afterInsert: [] | ||
}, | ||
el: function(name, options, children) { | ||
var capture, cb, child, el, fn, i, len, lookupObj, mods, ref1, type, types, value; | ||
if (((ref1 = this._elLookup) != null ? ref1[name] : void 0) != null) { | ||
el = this._elLookup[name].call(this, name); | ||
} else { | ||
el = document.createElement(name); | ||
} | ||
if (options != null) { | ||
for (name in options) { | ||
types = options[name]; | ||
lookupObj = this._attrLookup[name]; | ||
for (type in types) { | ||
value = types[type]; | ||
if (value.mods != null) { | ||
mods = value.mods; | ||
value = value.val; | ||
if (mods.camel) { | ||
name = camelize(name); | ||
} | ||
ref: { | ||
"#": function(el, val) { | ||
return this[val] = el; | ||
} | ||
} | ||
}, | ||
methods: { | ||
"$structure": { | ||
beforeInsert: [], | ||
afterInsert: [] | ||
}, | ||
el: function(name, options, children) { | ||
var capture, cb, child, el, fn, i, len, lookupObj, mods, ref1, type, types, value; | ||
if (((ref1 = this._elLookup) != null ? ref1[name] : void 0) != null) { | ||
el = this._elLookup[name].call(this, name); | ||
} else { | ||
el = document.createElement(name); | ||
} | ||
if (options != null) { | ||
for (name in options) { | ||
types = options[name]; | ||
lookupObj = this._attrLookup[name]; | ||
for (type in types) { | ||
value = types[type]; | ||
if (value.mods != null) { | ||
mods = value.mods; | ||
value = value.val; | ||
if (mods.camel) { | ||
name = camelize(name); | ||
} | ||
if (lookupObj != null) { | ||
if (lookupObj[type] != null) { | ||
lookupObj[type].call(this, el, value, mods); | ||
continue; | ||
} | ||
if (lookupObj != null) { | ||
if (lookupObj[type] != null) { | ||
lookupObj[type].call(this, el, value, mods); | ||
continue; | ||
} | ||
if(process.env.NODE_ENV!=='production' && lookupObj[type] == null){console.warn(type + name + ' found, but not expected')}; | ||
} | ||
switch (type) { | ||
case "$": | ||
this.$watch.path({ | ||
path: value, | ||
cbs: (function(el, name, val) { | ||
return el[name] = val; | ||
}).bind(this, el, name) | ||
}); | ||
break; | ||
case ":": | ||
this.$watch.path({ | ||
path: value, | ||
cbs: this.$setAttribute.bind(this, el, name) | ||
}); | ||
break; | ||
case "@": | ||
if (isString(value)) { | ||
value = this.$path.toValue({ | ||
path: value | ||
}).value; | ||
} | ||
if(process.env.NODE_ENV!=='production' && lookupObj[type] == null){console.warn(type + name + ' found, but not expected')}; | ||
} | ||
switch (type) { | ||
case "$": | ||
this.$watch.path({ | ||
path: value, | ||
cbs: (function(el, name, val) { | ||
return el[name] = val; | ||
}).bind(this, el, name) | ||
}); | ||
break; | ||
case ":": | ||
this.$watch.path({ | ||
path: value, | ||
cbs: this.$setAttribute.bind(this, el, name) | ||
}); | ||
break; | ||
case "@": | ||
if (isString(value)) { | ||
value = this.$path.toValue({ | ||
path: value | ||
}).value; | ||
} | ||
if (mods != null) { | ||
capture = mods.capture; | ||
fn = function(e) { | ||
if (mods.self && e.target !== el) { | ||
return; | ||
if (mods != null) { | ||
capture = mods.capture; | ||
fn = function(e) { | ||
if (mods.self && e.target !== el) { | ||
return; | ||
} | ||
if (mods.notPrevented && e.defaultPrevented) { | ||
return; | ||
} | ||
value.apply(this, arguments); | ||
if (mods.prevent) { | ||
e.preventDefault(); | ||
} | ||
if (mods.stop) { | ||
e.stopPropagation(); | ||
} | ||
if (mods.once) { | ||
return el.removeEventListener(name, fn); | ||
} | ||
}; | ||
} else { | ||
capture = null; | ||
fn = value; | ||
} | ||
fn = fn.bind(this); | ||
el.addEventListener(name, fn, capture); | ||
break; | ||
case "~": | ||
if (this[name] == null) { | ||
this[name] = (function(_this) { | ||
return function() { | ||
var cb, i, len, ref2, results; | ||
ref2 = _this[name]._cbs; | ||
results = []; | ||
for (i = 0, len = ref2.length; i < len; i++) { | ||
cb = ref2[i]; | ||
results.push(cb.apply(null, arguments)); | ||
} | ||
if (mods.notPrevented && e.defaultPrevented) { | ||
return; | ||
} | ||
value.apply(this, arguments); | ||
if (mods.prevent) { | ||
e.preventDefault(); | ||
} | ||
if (mods.stop) { | ||
e.stopPropagation(); | ||
} | ||
if (mods.once) { | ||
return el.removeEventListener(name, fn); | ||
} | ||
return results; | ||
}; | ||
} else { | ||
capture = null; | ||
fn = value; | ||
} | ||
fn = fn.bind(this); | ||
el.addEventListener(name, fn, capture); | ||
break; | ||
case "~": | ||
if (this[name] == null) { | ||
this[name] = (function(_this) { | ||
return function() { | ||
var cb, i, len, ref2, results; | ||
ref2 = _this[name]._cbs; | ||
results = []; | ||
for (i = 0, len = ref2.length; i < len; i++) { | ||
cb = ref2[i]; | ||
results.push(cb.apply(null, arguments)); | ||
} | ||
return results; | ||
}; | ||
})(this); | ||
} | ||
if (mods != null ? mods.event : void 0) { | ||
cb = (function(el, value, e) { | ||
return el.dispatchEvent(value, e); | ||
}).bind(null, el, value); | ||
} else { | ||
cb = (function() { | ||
var args, el, value; | ||
el = arguments[0], value = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : []; | ||
return el[value].apply(null, args); | ||
}).bind(null, el, value); | ||
} | ||
this[name]._cbs.push(cb); | ||
break; | ||
default: | ||
el.setAttribute(name, value); | ||
} | ||
})(this); | ||
} | ||
if (mods != null ? mods.event : void 0) { | ||
cb = (function(el, value, e) { | ||
return el.dispatchEvent(value, e); | ||
}).bind(null, el, value); | ||
} else { | ||
cb = (function() { | ||
var args, el, value; | ||
el = arguments[0], value = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : []; | ||
return el[value].apply(null, args); | ||
}).bind(null, el, value); | ||
} | ||
this[name]._cbs.push(cb); | ||
break; | ||
default: | ||
el.setAttribute(name, value); | ||
} | ||
} | ||
} | ||
if (children != null) { | ||
for (i = 0, len = children.length; i < len; i++) { | ||
child = children[i]; | ||
if (isString(child)) { | ||
this._slots[child] = el; | ||
} else { | ||
el.appendChild(child); | ||
} | ||
} | ||
} | ||
return el; | ||
} | ||
}, | ||
created: function() { | ||
return this._slots = {}; | ||
}, | ||
connectedCallback: function() { | ||
var child, el, fn, i, j, k, l, len, len1, len2, len3, ref1, ref2, ref3, ref4, ref5, results, slot, structure; | ||
if (this._isFirstConnect && (this.structure != null)) { | ||
structure = arrayize(this.structure()); | ||
ref1 = this.$structure.beforeInsert; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
fn.call(this, structure); | ||
} | ||
ref2 = this.children; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
child = ref2[j]; | ||
slot = child.getAttribute("slot"); | ||
if (slot != null) { | ||
if ((ref3 = this._slots[slot]) != null) { | ||
ref3.appendChild(slot); | ||
} | ||
if (children != null) { | ||
for (i = 0, len = children.length; i < len; i++) { | ||
child = children[i]; | ||
if (isString(child)) { | ||
this._slots[child] = el; | ||
} else { | ||
if ((ref4 = this._slots["default"]) != null) { | ||
ref4.appendChild(child); | ||
} | ||
el.appendChild(child); | ||
} | ||
} | ||
for (k = 0, len2 = structure.length; k < len2; k++) { | ||
el = structure[k]; | ||
if (isString(el)) { | ||
this._slots[el] = this; | ||
} else { | ||
this.appendChild(el); | ||
} | ||
return el; | ||
} | ||
}, | ||
created: function() { | ||
return this._slots = {}; | ||
}, | ||
connectedCallback: function() { | ||
var child, el, fn, i, j, k, l, len, len1, len2, len3, ref1, ref2, ref3, ref4, ref5, results, slot, structure; | ||
if (this._isFirstConnect && (this.structure != null)) { | ||
structure = arrayize(this.structure()); | ||
ref1 = this.$structure.beforeInsert; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
fn = ref1[i]; | ||
fn.call(this, structure); | ||
} | ||
ref2 = this.children; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
child = ref2[j]; | ||
slot = child.getAttribute("slot"); | ||
if (slot != null) { | ||
if ((ref3 = this._slots[slot]) != null) { | ||
ref3.appendChild(slot); | ||
} | ||
} else { | ||
if ((ref4 = this._slots["default"]) != null) { | ||
ref4.appendChild(child); | ||
} | ||
} | ||
ref5 = this.$structure.afterInsert; | ||
results = []; | ||
for (l = 0, len3 = ref5.length; l < len3; l++) { | ||
fn = ref5[l]; | ||
results.push(fn.call(this)); | ||
} | ||
for (k = 0, len2 = structure.length; k < len2; k++) { | ||
el = structure[k]; | ||
if (isString(el)) { | ||
this._slots[el] = this; | ||
} else { | ||
this.appendChild(el); | ||
} | ||
return results; | ||
} | ||
ref5 = this.$structure.afterInsert; | ||
results = []; | ||
for (l = 0, len3 = ref5.length; l < len3; l++) { | ||
fn = ref5[l]; | ||
results.push(fn.call(this)); | ||
} | ||
return results; | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
105
lib/style.js
@@ -1,62 +0,59 @@ | ||
(function() { | ||
var camelize, capitalize, prefixes, ref; | ||
var camelize, capitalize, prefixes, ref; | ||
prefixes = ["Webkit", "Moz", "ms"]; | ||
prefixes = ["Webkit", "Moz", "ms"]; | ||
ref = require("./_helpers"), camelize = ref.camelize, capitalize = ref.capitalize; | ||
ref = require("./_helpers"), camelize = ref.camelize, capitalize = ref.capitalize; | ||
module.exports = { | ||
_name: "style", | ||
_v: 1, | ||
_rebind: "$style", | ||
methods: { | ||
$style: { | ||
normalize: function(prop) { | ||
var i, len, prefix, prefixed; | ||
prop = camelize(prop); | ||
if (this.style[prop] != null) { | ||
return prop; | ||
module.exports = { | ||
_name: "style", | ||
_v: 1, | ||
_rebind: "$style", | ||
methods: { | ||
$style: { | ||
normalize: function(prop) { | ||
var i, len, prefix, prefixed; | ||
prop = camelize(prop); | ||
if (this.style[prop] != null) { | ||
return prop; | ||
} | ||
prop = capitalize(prop); | ||
for (i = 0, len = prefixes.length; i < len; i++) { | ||
prefix = prefixes[i]; | ||
prefixed = prefix + prop; | ||
if (this.style[prefixed] != null) { | ||
return prefixed; | ||
} | ||
prop = capitalize(prop); | ||
for (i = 0, len = prefixes.length; i < len; i++) { | ||
prefix = prefixes[i]; | ||
prefixed = prefix + prop; | ||
if (this.style[prefixed] != null) { | ||
return prefixed; | ||
} | ||
} | ||
return null; | ||
}, | ||
normalizeObj: function(obj) { | ||
var k, normalize, tmp, v; | ||
tmp = {}; | ||
normalize = this.$style.normalize; | ||
for (k in obj) { | ||
v = obj[k]; | ||
tmp[normalize(k)] = v; | ||
} | ||
return tmp; | ||
}, | ||
setNormalized: function(el, obj) { | ||
var k, results, v; | ||
results = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
results.push(el.style[k] = v); | ||
} | ||
return results; | ||
}, | ||
set: function(el, obj) { | ||
if (obj == null) { | ||
obj = el; | ||
el = this; | ||
} | ||
return this.$style.setNormalized(el, this.$style.normalizeObj(obj)); | ||
} | ||
return null; | ||
}, | ||
normalizeObj: function(obj) { | ||
var k, normalize, tmp, v; | ||
tmp = {}; | ||
normalize = this.$style.normalize; | ||
for (k in obj) { | ||
v = obj[k]; | ||
tmp[normalize(k)] = v; | ||
} | ||
return tmp; | ||
}, | ||
setNormalized: function(el, obj) { | ||
var k, results, v; | ||
results = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
results.push(el.style[k] = v); | ||
} | ||
return results; | ||
}, | ||
set: function(el, obj) { | ||
if (obj == null) { | ||
obj = el; | ||
el = this; | ||
} | ||
return this.$style.setNormalized(el, this.$style.normalizeObj(obj)); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,57 +0,54 @@ | ||
(function() { | ||
var parseStyleString; | ||
var parseStyleString; | ||
parseStyleString = function(str) { | ||
var cssprop, i, len, ref, result, splitted; | ||
result = {}; | ||
if (str != null) { | ||
ref = str.split(/;(?![^(]*\))/g); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
cssprop = ref[i]; | ||
if (cssprop != null) { | ||
splitted = cssprop.split(/:(.+)/); | ||
if (splitted.length > 1) { | ||
result[splitted[0].trim()] = splitted[1].trim(); | ||
} | ||
parseStyleString = function(str) { | ||
var cssprop, i, len, ref, result, splitted; | ||
result = {}; | ||
if (str != null) { | ||
ref = str.split(/;(?![^(]*\))/g); | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
cssprop = ref[i]; | ||
if (cssprop != null) { | ||
splitted = cssprop.split(/:(.+)/); | ||
if (splitted.length > 1) { | ||
result[splitted[0].trim()] = splitted[1].trim(); | ||
} | ||
} | ||
} | ||
return result; | ||
}; | ||
} | ||
return result; | ||
}; | ||
module.exports = { | ||
_name: "styles", | ||
_v: 1, | ||
_prio: 700, | ||
_mergers: require("./_merger").copy({ | ||
source: "styles" | ||
}), | ||
mixins: [require("./style"), require("./combined")], | ||
connectedCallback: function() { | ||
if (this._isFirstConnect) { | ||
return this.$combined({ | ||
path: "styles", | ||
value: this.styles, | ||
parseProp: parseStyleString, | ||
normalize: this.$style.normalizeObj, | ||
cbFactory: function(name) { | ||
var el; | ||
if (name === "this") { | ||
el = this; | ||
} else { | ||
el = this[name]; | ||
module.exports = { | ||
_name: "styles", | ||
_v: 1, | ||
_prio: 700, | ||
_mergers: require("./_merger").copy({ | ||
source: "styles" | ||
}), | ||
mixins: [require("./style"), require("./combined")], | ||
connectedCallback: function() { | ||
if (this._isFirstConnect) { | ||
return this.$combined({ | ||
path: "styles", | ||
value: this.styles, | ||
parseProp: parseStyleString, | ||
normalize: this.$style.normalizeObj, | ||
cbFactory: function(name) { | ||
var el; | ||
if (name === "this") { | ||
el = this; | ||
} else { | ||
el = this[name]; | ||
} | ||
return [ | ||
function(val) { | ||
return this.$style.setNormalized(el, val); | ||
} | ||
return [ | ||
function(val) { | ||
return this.$style.setNormalized(el, val); | ||
} | ||
]; | ||
} | ||
}); | ||
} | ||
]; | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,31 +0,28 @@ | ||
(function() { | ||
var createSvgElement, i, len, lookup, name, svgTags; | ||
var createSvgElement, i, len, lookup, name, svgTags; | ||
createSvgElement = function(name) { | ||
var el; | ||
el = document.createElementNS("http://www.w3.org/2000/svg", name); | ||
if (name === "svg") { | ||
el.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink"); | ||
} | ||
return el; | ||
}; | ||
createSvgElement = function(name) { | ||
var el; | ||
el = document.createElementNS("http://www.w3.org/2000/svg", name); | ||
if (name === "svg") { | ||
el.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink"); | ||
} | ||
return el; | ||
}; | ||
svgTags = ["svg", "animate", "circle", "clippath", "cursor", "defs", "desc", "ellipse", "filter", "font-face", "foreignObject", "g", "glyph", "image", "line", "marker", "mask", "missing-glyph", "path", "pattern", "polygon", "polyline", "rect", "switch", "symbol", "text", "textpath", "tspan", "use", "view"]; | ||
svgTags = ["svg", "animate", "circle", "clippath", "cursor", "defs", "desc", "ellipse", "filter", "font-face", "foreignObject", "g", "glyph", "image", "line", "marker", "mask", "missing-glyph", "path", "pattern", "polygon", "polyline", "rect", "switch", "symbol", "text", "textpath", "tspan", "use", "view"]; | ||
lookup = {}; | ||
lookup = {}; | ||
for (i = 0, len = svgTags.length; i < len; i++) { | ||
name = svgTags[i]; | ||
lookup[name] = createSvgElement; | ||
} | ||
for (i = 0, len = svgTags.length; i < len; i++) { | ||
name = svgTags[i]; | ||
lookup[name] = createSvgElement; | ||
} | ||
module.exports = { | ||
_name: "svg", | ||
_v: 1, | ||
_elLookup: lookup, | ||
mixins: [require("./structure")] | ||
}; | ||
module.exports = { | ||
_name: "svg", | ||
_v: 1, | ||
_elLookup: lookup, | ||
mixins: [require("./structure")] | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,39 +0,36 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "tests", | ||
_prio: 0, | ||
_v: 1, | ||
_mergers: [ | ||
{ | ||
source: "tests", | ||
setup: function() { | ||
return { | ||
iterate: function() {} | ||
}; | ||
}, | ||
finisher: function(obj) { | ||
var base; | ||
if (process.env.NODE_ENV === "test") { | ||
if (window.ceri == null) { | ||
window.ceri = {}; | ||
} | ||
if ((base = window.ceri).tests == null) { | ||
base.tests = []; | ||
} | ||
return window.ceri.tests.push(obj); | ||
module.exports = { | ||
_name: "tests", | ||
_prio: 0, | ||
_v: 1, | ||
_mergers: [ | ||
{ | ||
source: "tests", | ||
setup: function() { | ||
return { | ||
iterate: function() {} | ||
}; | ||
}, | ||
finisher: function(obj) { | ||
var base; | ||
if (process.env.NODE_ENV === "test") { | ||
if (window.ceri == null) { | ||
window.ceri = {}; | ||
} | ||
if ((base = window.ceri).tests == null) { | ||
base.tests = []; | ||
} | ||
return window.ceri.tests.push(obj); | ||
} | ||
} | ||
], | ||
created: function() { | ||
if (process.env.NODE_ENV === "test") { | ||
return this.$nextTick(function() { | ||
return typeof this.tests === "function" ? this.tests(this) : void 0; | ||
}); | ||
} | ||
} | ||
}; | ||
], | ||
created: function() { | ||
if (process.env.NODE_ENV === "test") { | ||
return this.$nextTick(function() { | ||
return typeof this.tests === "function" ? this.tests(this) : void 0; | ||
}); | ||
} | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,13 +0,10 @@ | ||
(function() { | ||
module.exports = { | ||
_name: "util", | ||
_prio: 0, | ||
_v: 1, | ||
methods: { | ||
util: require("./_helpers") | ||
} | ||
}; | ||
module.exports = { | ||
_name: "util", | ||
_prio: 0, | ||
_v: 1, | ||
methods: { | ||
util: require("./_helpers") | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
445
lib/watch.js
@@ -1,193 +0,105 @@ | ||
(function() { | ||
var arrayProto, arrayize, clone, getID, i, isArray, isObject, isString, len, merger, method, ref, ref1, watchStr, | ||
hasProp = {}.hasOwnProperty; | ||
var arrayProto, arrayize, clone, getID, i, isArray, isObject, isString, len, merger, method, ref, ref1, watchStr, | ||
hasProp = {}.hasOwnProperty; | ||
ref = require("./_helpers"), arrayize = ref.arrayize, isString = ref.isString, isArray = ref.isArray, isObject = ref.isObject, clone = ref.clone, getID = ref.getID; | ||
ref = require("./_helpers"), arrayize = ref.arrayize, isString = ref.isString, isArray = ref.isArray, isObject = ref.isObject, clone = ref.clone, getID = ref.getID; | ||
merger = require("./_merger"); | ||
merger = require("./_merger"); | ||
arrayProto = Object.create(Array.prototype); | ||
arrayProto = Object.create(Array.prototype); | ||
watchStr = "__watch__"; | ||
watchStr = "__watch__"; | ||
ref1 = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
method = ref1[i]; | ||
arrayProto[method] = function() { | ||
this[watchStr].notify(); | ||
return Array.prototype[method].apply(this, arguments); | ||
}; | ||
ref1 = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
method = ref1[i]; | ||
arrayProto[method] = function() { | ||
this[watchStr].notify(); | ||
return Array.prototype[method].apply(this, arguments); | ||
}; | ||
/*fn = (method, cb) -> -> | ||
cb?.apply(@,arguments) | ||
@[watchStr].notify(@) | ||
return arrayProto[method].apply @, arguments | ||
switch method | ||
when 'push','unshift' | ||
arrayProto[method] = fn method, -> | ||
o = @[watchStr] | ||
o.init(arr: arguments, notify: o.notify) | ||
when 'splice' | ||
arrayProto[method] = fn method, -> | ||
o = @[watchStr] | ||
o.init(arr: arguments.slice(2), notify: o.notify) | ||
else | ||
arrayProto[method] = fn method | ||
*/ | ||
} | ||
/*fn = (method, cb) -> -> | ||
cb?.apply(@,arguments) | ||
@[watchStr].notify(@) | ||
return arrayProto[method].apply @, arguments | ||
switch method | ||
when 'push','unshift' | ||
arrayProto[method] = fn method, -> | ||
o = @[watchStr] | ||
o.init(arr: arguments, notify: o.notify) | ||
when 'splice' | ||
arrayProto[method] = fn method, -> | ||
o = @[watchStr] | ||
o.init(arr: arguments.slice(2), notify: o.notify) | ||
else | ||
arrayProto[method] = fn method | ||
*/ | ||
} | ||
module.exports = { | ||
_name: "watch", | ||
_prio: 1000, | ||
_v: 1, | ||
_mergers: [ | ||
merger.copy({ | ||
source: "watch" | ||
}), merger.concat({ | ||
source: "data" | ||
}) | ||
], | ||
_rebind: "$watch", | ||
mixins: [require("./path")], | ||
methods: { | ||
$watch: { | ||
__w: {}, | ||
getObj: function(o) { | ||
var obj, ref2; | ||
if ((obj = (ref2 = o.value) != null ? ref2[watchStr] : void 0) != null) { | ||
this.$watch.setObj(obj); | ||
return obj; | ||
} else if ((o.path != null) && ((obj = this.$watch.__w[o.path]) != null)) { | ||
return obj; | ||
} | ||
return null; | ||
}, | ||
setObj: function(o) { | ||
return this.$watch.__w[o.path] = o; | ||
}, | ||
processNewValue: function(o) { | ||
var child, k, obj, proto, v; | ||
child = o.value; | ||
if (child != null ? child.__proto__ : void 0) { | ||
obj = {}; | ||
obj[watchStr] = { | ||
value: o | ||
}; | ||
if (isArray(child)) { | ||
proto = arrayProto; | ||
} else { | ||
proto = child.__proto__; | ||
if (isObject(child) && !child._isCeri) { | ||
for (k in child) { | ||
if (!hasProp.call(child, k)) continue; | ||
v = child[k]; | ||
this.$watch.path({ | ||
parent: child, | ||
name: k, | ||
value: v, | ||
parentPath: o.path | ||
}); | ||
} | ||
} | ||
} | ||
return child.__proto__ = Object.create(proto, obj); | ||
} | ||
}, | ||
path: function(o) { | ||
var cb, getter, initVal, j, len1, obj, ref2, setter; | ||
if ((o.parentPath != null) && (o.name != null)) { | ||
o.path = o.parentPath + "." + o.name; | ||
} | ||
if(process.env.NODE_ENV!=='production' && o.path == null){console.warn('$watch.path requires path')}; | ||
this.$path.toNameAndParent(o); | ||
this.$watch.parse(o); | ||
if (!o.parent) { | ||
if ((obj = this.$watch.getObj(o)) != null) { | ||
ref2 = o.cbs; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
cb = ref2[j]; | ||
obj.cbs.push(cb); | ||
} | ||
if(process.env.NODE_ENV!=='production' && o.value != null){console.warn('can\'t set ' + o.value + ' on ' + o.path + ' yet. Parent isn\'t setted yet')}; | ||
} else { | ||
return this.$watch.setObj(o); | ||
} | ||
module.exports = { | ||
_name: "watch", | ||
_prio: 1000, | ||
_v: 1, | ||
_mergers: [ | ||
merger.copy({ | ||
source: "watch" | ||
}), merger.concat({ | ||
source: "data" | ||
}) | ||
], | ||
_rebind: "$watch", | ||
mixins: [require("./path")], | ||
methods: { | ||
$watch: { | ||
__w: {}, | ||
getObj: function(o) { | ||
var obj, ref2; | ||
if ((obj = (ref2 = o.value) != null ? ref2[watchStr] : void 0) != null) { | ||
this.$watch.setObj(obj); | ||
return obj; | ||
} else if ((o.path != null) && ((obj = this.$watch.__w[o.path]) != null)) { | ||
return obj; | ||
} | ||
return null; | ||
}, | ||
setObj: function(o) { | ||
return this.$watch.__w[o.path] = o; | ||
}, | ||
processNewValue: function(o) { | ||
var child, k, obj, proto, v; | ||
child = o.value; | ||
if (child != null ? child.__proto__ : void 0) { | ||
obj = {}; | ||
obj[watchStr] = { | ||
value: o | ||
}; | ||
if (isArray(child)) { | ||
proto = arrayProto; | ||
} else { | ||
o = this.$watch.init(o); | ||
if (o) { | ||
o.id = getID(); | ||
o.notify = function(val, oldVal) { | ||
var l, len2, ref3; | ||
ref3 = o.cbs; | ||
for (l = 0, len2 = ref3.length; l < len2; l++) { | ||
cb = ref3[l]; | ||
try { | ||
cb(val, oldVal); | ||
} catch (error) {} | ||
} | ||
}; | ||
getter = function() { | ||
if ((window.__ceriDeps != null) && (window.__ceriDeps[o.id] == null)) { | ||
o.cbs.push(window.__ceriDeps(o.id).notify); | ||
} | ||
return o.value; | ||
}; | ||
setter = function(newVal) { | ||
var oldVal; | ||
oldVal = o.value; | ||
o.value = newVal; | ||
this.$watch.processNewValue(o); | ||
return o.notify(newVal, oldVal); | ||
}; | ||
if (o.initial) { | ||
if (o.value != null) { | ||
initVal = o.value; | ||
delete o.value; | ||
} else { | ||
initVal = o.parent[o.name]; | ||
} | ||
} else { | ||
if (o.value == null) { | ||
o.value = o.parent[o.name]; | ||
} | ||
proto = child.__proto__; | ||
if (isObject(child) && !child._isCeri) { | ||
for (k in child) { | ||
if (!hasProp.call(child, k)) continue; | ||
v = child[k]; | ||
this.$watch.path({ | ||
parent: child, | ||
name: k, | ||
value: v, | ||
parentPath: o.path | ||
}); | ||
} | ||
Object.defineProperty(o.parent, o.name, { | ||
get: getter.bind(this), | ||
set: setter.bind(this) | ||
}); | ||
if (o.initial) { | ||
return o.parent[o.name] = initVal; | ||
} | ||
} | ||
} | ||
}, | ||
parse: function(obj, shouldClone) { | ||
if (!isObject(obj)) { | ||
obj = { | ||
cbs: obj | ||
}; | ||
} else if (shouldClone) { | ||
obj = clone(obj); | ||
} | ||
if (!obj.__parsed__) { | ||
obj.cbs = arrayize(obj.cbs).map((function(_this) { | ||
return function(cb) { | ||
if (isString(cb)) { | ||
if(process.env.NODE_ENV!=='production' && !_this[cb]){console.warn('method ' + cb + ' not found')}; | ||
return _this[cb].bind(_this); | ||
} | ||
return cb.bind(_this); | ||
}; | ||
})(this)); | ||
if (obj.initial == null) { | ||
obj.initial = true; | ||
} | ||
obj.__parsed__ = true; | ||
} | ||
return obj; | ||
}, | ||
init: function(o) { | ||
var cb, j, l, len1, len2, obj, ref2, ref3, val, w; | ||
obj = this.$watch.getObj(o); | ||
if (obj != null ? obj.__init__ : void 0) { | ||
return child.__proto__ = Object.create(proto, obj); | ||
} | ||
}, | ||
path: function(o) { | ||
var cb, getter, initVal, j, len1, obj, ref2, setter; | ||
if ((o.parentPath != null) && (o.name != null)) { | ||
o.path = o.parentPath + "." + o.name; | ||
} | ||
if(process.env.NODE_ENV!=='production' && o.path == null){console.warn('$watch.path requires path')}; | ||
this.$path.toNameAndParent(o); | ||
this.$watch.parse(o); | ||
if (!o.parent) { | ||
if ((obj = this.$watch.getObj(o)) != null) { | ||
ref2 = o.cbs; | ||
@@ -198,56 +110,141 @@ for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
} | ||
if (o.value != null) { | ||
if (o.parent[o.name] !== o.value) { | ||
o.parent[o.name] = o.value; | ||
} | ||
} else if (o.initial) { | ||
val = o.parent[o.name]; | ||
if(process.env.NODE_ENV!=='production' && o.value != null){console.warn('can\'t set ' + o.value + ' on ' + o.path + ' yet. Parent isn\'t setted yet')}; | ||
} else { | ||
return this.$watch.setObj(o); | ||
} | ||
} else { | ||
o = this.$watch.init(o); | ||
if (o) { | ||
o.id = getID(); | ||
o.notify = function(val, oldVal) { | ||
var l, len2, ref3; | ||
ref3 = o.cbs; | ||
for (l = 0, len2 = ref3.length; l < len2; l++) { | ||
cb = ref3[l]; | ||
cb(val); | ||
try { | ||
cb(val, oldVal); | ||
} catch (error) {} | ||
} | ||
}; | ||
getter = function() { | ||
if ((window.__ceriDeps != null) && (window.__ceriDeps[o.id] == null)) { | ||
o.cbs.push(window.__ceriDeps(o.id).notify); | ||
} | ||
return o.value; | ||
}; | ||
setter = function(newVal) { | ||
var oldVal; | ||
oldVal = o.value; | ||
o.value = newVal; | ||
this.$watch.processNewValue(o); | ||
return o.notify(newVal, oldVal); | ||
}; | ||
if (o.initial) { | ||
if (o.value != null) { | ||
initVal = o.value; | ||
delete o.value; | ||
} else { | ||
initVal = o.parent[o.name]; | ||
} | ||
} else { | ||
if (o.value == null) { | ||
o.value = o.parent[o.name]; | ||
} | ||
} | ||
} else { | ||
o.__init__ = true; | ||
if (obj) { | ||
o.cbs = obj.cbs.concat(o.cbs); | ||
Object.defineProperty(o.parent, o.name, { | ||
get: getter.bind(this), | ||
set: setter.bind(this) | ||
}); | ||
if (o.initial) { | ||
return o.parent[o.name] = initVal; | ||
} | ||
w = this.$watch.parse(this.watch[o.path], true); | ||
o.cbs = o.cbs.concat(w.cbs); | ||
this.$watch.setObj(o); | ||
return o; | ||
} | ||
return false; | ||
} | ||
} | ||
}, | ||
created: function() { | ||
var fn, j, k, len1, obj, ref2, results, v; | ||
ref2 = this.data; | ||
results = []; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
fn = ref2[j]; | ||
obj = fn.call(this); | ||
results.push((function() { | ||
var results1; | ||
results1 = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
results1.push(this.$watch.path({ | ||
parent: this, | ||
name: k, | ||
value: v, | ||
path: k | ||
})); | ||
}, | ||
parse: function(obj, shouldClone) { | ||
if (!isObject(obj)) { | ||
obj = { | ||
cbs: obj | ||
}; | ||
} else if (shouldClone) { | ||
obj = clone(obj); | ||
} | ||
if (!obj.__parsed__) { | ||
obj.cbs = arrayize(obj.cbs).map((function(_this) { | ||
return function(cb) { | ||
if (isString(cb)) { | ||
if(process.env.NODE_ENV!=='production' && !_this[cb]){console.warn('method ' + cb + ' not found')}; | ||
return _this[cb].bind(_this); | ||
} | ||
return cb.bind(_this); | ||
}; | ||
})(this)); | ||
if (obj.initial == null) { | ||
obj.initial = true; | ||
} | ||
return results1; | ||
}).call(this)); | ||
obj.__parsed__ = true; | ||
} | ||
return obj; | ||
}, | ||
init: function(o) { | ||
var cb, j, l, len1, len2, obj, ref2, ref3, val, w; | ||
obj = this.$watch.getObj(o); | ||
if (obj != null ? obj.__init__ : void 0) { | ||
ref2 = o.cbs; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
cb = ref2[j]; | ||
obj.cbs.push(cb); | ||
} | ||
if (o.value != null) { | ||
if (o.parent[o.name] !== o.value) { | ||
o.parent[o.name] = o.value; | ||
} | ||
} else if (o.initial) { | ||
val = o.parent[o.name]; | ||
ref3 = o.cbs; | ||
for (l = 0, len2 = ref3.length; l < len2; l++) { | ||
cb = ref3[l]; | ||
cb(val); | ||
} | ||
} | ||
} else { | ||
o.__init__ = true; | ||
if (obj) { | ||
o.cbs = obj.cbs.concat(o.cbs); | ||
} | ||
w = this.$watch.parse(this.watch[o.path], true); | ||
o.cbs = o.cbs.concat(w.cbs); | ||
this.$watch.setObj(o); | ||
return o; | ||
} | ||
return false; | ||
} | ||
return results; | ||
} | ||
}; | ||
}, | ||
created: function() { | ||
var fn, j, k, len1, obj, ref2, results, v; | ||
ref2 = this.data; | ||
results = []; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
fn = ref2[j]; | ||
obj = fn.call(this); | ||
results.push((function() { | ||
var results1; | ||
results1 = []; | ||
for (k in obj) { | ||
v = obj[k]; | ||
results1.push(this.$watch.path({ | ||
parent: this, | ||
name: k, | ||
value: v, | ||
path: k | ||
})); | ||
} | ||
return results1; | ||
}).call(this)); | ||
} | ||
return results; | ||
} | ||
}; | ||
; | ||
}).call(this); | ||
; |
@@ -1,12 +0,26 @@ | ||
(function() { | ||
var ceri; | ||
var ceri; | ||
ceri = require("./ceri"); | ||
ceri = require("./ceri"); | ||
module.exports = function(parent, obj) { | ||
var cls, k, v; | ||
if (obj == null) { | ||
obj = parent; | ||
parent = HTMLElement; | ||
module.exports = function(parent, obj) { | ||
var cls, e, k, v; | ||
if (obj == null) { | ||
obj = parent; | ||
parent = HTMLElement; | ||
} | ||
try { | ||
if (window.customElements.define.name !== "define") { | ||
throw new Error("polyfill detected - fallback to ES5 class"); | ||
} | ||
cls = class Ceri extends parent { | ||
constructor () { | ||
super() | ||
this._crCb.forEach(cb => { | ||
cb.call(this) | ||
}) | ||
return this | ||
} | ||
}; | ||
} catch (error) { | ||
e = error; | ||
cls = obj.constructor = function(self) { | ||
@@ -22,10 +36,9 @@ var fn, i, len, ref; | ||
}; | ||
cls.prototype = Object.create(parent.prototype); | ||
for (k in obj) { | ||
v = obj[k]; | ||
cls.prototype[k] = v; | ||
} | ||
return ceri(cls); | ||
}; | ||
}).call(this); | ||
} | ||
cls.prototype = Object.create(parent.prototype); | ||
for (k in obj) { | ||
v = obj[k]; | ||
cls.prototype[k] = v; | ||
} | ||
return ceri(cls); | ||
}; |
{ | ||
"name": "ceri", | ||
"description": "Custom Elements enRIched", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"homepage": "https://github.com/cerijs/", | ||
@@ -52,8 +52,6 @@ "author": { | ||
"build": "run-npm build:*", | ||
"build:coffee": "coffee --no-header --compile --output lib/ src/*.coffee", | ||
"build:removeTests": "coffee ./bundleBuilder.coffee", | ||
"build:compile": "coffee ./compiler.coffee", | ||
"build:ceri": "ceri-compiler --out lib/ lib/*", | ||
"watch": "run-npm -p watch:*", | ||
"watch:coffee": "coffee --no-header --watch --output lib/ src/*.coffee", | ||
"watch:removeTests": "coffee ./bundleBuilder.coffee --watch", | ||
"watch:compile": "coffee ./compiler.coffee --watch", | ||
"watch:karma": "karma start --browsers Chromium --auto-watch", | ||
@@ -60,0 +58,0 @@ "test": "karma start --single-run", |
@@ -32,3 +32,4 @@ # ceriJS | ||
You have to install and use the lightweight custom-element polyfill: | ||
Custom elements aren't widely adopted, yet. | ||
So you have to use the lightweight custom-element polyfill: | ||
```sh | ||
@@ -39,7 +40,18 @@ npm install --save-dev document-register-element | ||
```js | ||
require("document-register-element/pony")(global,"force") | ||
// force is required for now, as native custom elements requires | ||
// ES6 classes which are not widely supported | ||
// always load the polyfill | ||
require("document-register-element") | ||
// load the polyfill only when needed - with the help of webpack | ||
function polyfillCE() { | ||
require.ensure([], require => { | ||
require("document-register-element") | ||
startupApp() // your startup code depending on window.customElements | ||
},"cePoly") | ||
} | ||
if !window.customElements | ||
polyfillCE() | ||
else | ||
startupApp() // your startup code depending on window.customElements | ||
``` | ||
Afterwards you can register a component easily: | ||
To register a component: | ||
```js | ||
@@ -70,6 +82,7 @@ // the name should contain at least one hyphen | ||
```coffee | ||
# main file of your component | ||
ceri = require "ceri" | ||
module.exports = ceri class ComponentName extends HTMLElement | ||
mixins:[ | ||
# the wrapper creates a ES5 class (prototype chain) and calls ceri on it | ||
ceri = require "ceri/lib/wrapper" | ||
# the component | ||
module.exports = ceri | ||
mixins: [ | ||
require "ceri/lib/watch" | ||
@@ -89,6 +102,6 @@ require "ceri/lib/structure" | ||
- Required style should be managed in `style` attributes | ||
- Required style for features should be managed in `style` attributes | ||
- Optional style should be delivered in one or multiple "theme" css files alongside your component | ||
- Use a mixin only if it helps to reduce complexity in your usecase. They don't come for free | ||
- HTMLElement has alot of properties, try to not conflict with them | ||
- Use a mixin only if it helps to reduce complexity in your use-case. They don't come for free | ||
- HTMLElement has a lot of properties, try to not conflict with them | ||
@@ -99,16 +112,4 @@ ### Reactions | ||
For setup code use `created` instead. | ||
All `created` callbacks will be called infront of the first `connectedCallback`. | ||
This can be problematic if you want to manipulate the component after creation, but before inserting. | ||
All `created` callbacks will be called in the constructor | ||
Alternatively you can call all `created` callbacks manualy in your constructor: | ||
```coffee | ||
ceri class SomeClass extends HTMLElement | ||
constructor: -> | ||
super() | ||
@_created = true # so they wont get called again | ||
for fn in @_c2Cb | ||
fn.call(@) | ||
``` | ||
### List of mixins | ||
@@ -138,2 +139,3 @@ Name | Links| Short description | ||
[#if](#if) | [doc](#if) [src](src/#if.coffee) | toggle element | ||
[#show](#show) | [doc](#show) [src](src/#show.coffee) | toggle visibility of an element | ||
@@ -408,5 +410,12 @@ ### Template attributes | ||
structure: template 1, """<div #if=visible></div>""" | ||
data: -> | ||
visible: true | ||
data: -> visible: true | ||
``` | ||
#### #show | ||
toggle visibility of an element | ||
```coffee | ||
mixins: [ require("ceri/lib/#show") ] | ||
# usage with structure and watch | ||
structure: template 1, """<div #show=visible></div>""" | ||
data: -> visible: true | ||
``` | ||
@@ -413,0 +422,0 @@ |
443
2.07%62985
-5.5%1669
-1.88%