From 2d727055fc2bfb9977819f899d9f6ee61cc3fb3c Mon Sep 17 00:00:00 2001 From: David Higginbotham Date: Tue, 15 Sep 2015 17:32:49 -0600 Subject: [PATCH] was playing around with dataset, and some other perf opts, removing dataset --- .publish | 2 +- dist/murk.js | 2 +- dist/murk.js.gz | Bin 1476 -> 1449 bytes examples/build/templates/basic-example.tmpl | 2 +- examples/build/templates/repeat-example.tmpl | 2 +- examples/index.html | 4 +- examples/js/murk.js | 54 ++++++++----------- src/murk.js | 54 ++++++++----------- 8 files changed, 50 insertions(+), 70 deletions(-) diff --git a/.publish b/.publish index d98021b..36264ac 160000 --- a/.publish +++ b/.publish @@ -1 +1 @@ -Subproject commit d98021b8b49b6b688deeee44415289dd2a7bb72a +Subproject commit 36264ac3d7caa8d08f5ec7da0ca686df70859508 diff --git a/dist/murk.js b/dist/murk.js index 39e46c5..42837d0 100644 --- a/dist/murk.js +++ b/dist/murk.js @@ -1 +1 @@ -!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t:window[e]=t}("murk",function e(t){function r(e,t,r){return"boolean"==typeof t&&"undefined"==typeof r&&(r=t,t=r),r="undefined"!=typeof r?r:!0,"undefined"!=typeof t&&"string"==typeof e?(x.model[e]=t,x.elems.hasOwnProperty(e)&&l(x.elems[e]),this):(r?P(x.model,e):x.model=e,n(),this)}function o(e){return"undefined"!=typeof e?x.model.hasOwnProperty(e)?x.model[e]:null:x.model}function n(){var e=x.dom.length?x.dom:i();Array.prototype.forEach.call(e,l)}function s(e){e="undefined"==typeof e?document:e;var t=i(e);Array.prototype.forEach.call(t,l)}function i(e){return e="undefined"==typeof e?document:e,e.getElementsByTagName("*")}function l(e){var t,r;t=b(e),r=t(v.selectorPrefix),r&&(t(v.selectorPrefix+"-id")||t(v.selectorPrefix+"-id",v.id),t(v.selectorPrefix+"-id")==v.id&&(x.elems.hasOwnProperty(r)||(x.elems[r]=e,~x.keys.indexOf(r)||(x.keys.push(r),x.dom.push(e)),e.innerHTML&&!x.model.hasOwnProperty(r)&&(x.model[r]=e.innerHTML)),x.model.hasOwnProperty(r)&&(a(r),++x.totalCount)))}function a(e){x.subscribers.hasOwnProperty(e)||(x.subscribers[e]=Array.prototype.slice.call(v.defaultSubscribers));for(var t,r=Array.prototype.slice.call(x.subscribers[e]);t=r.shift();)t.call(x.elems[e],e)}function f(e,t){function r(e){x.subscribers.hasOwnProperty(e)||(x.subscribers[e]=Array.prototype.slice.call(v.defaultSubscribers)),x.subscribers[e].push(t)}return e instanceof Array||(e=[e]),Array.prototype.forEach.call(e,r),this}function c(e){var t,r,o=b(e);if(o&&(t=o(v.selectorPrefix+"-repeat-key"),r=o(v.selectorPrefix+"-repeat-bind"),t&&this.hasOwnProperty(t)&&(e.innerHTML!=this[t]&&m(e,this[t]),r))){var n=this.$key+"."+t;o(v.selectorPrefix)||o(v.selectorPrefix,n),l(e)}}function d(e){var t,r,o,n,s;if(x.model[e]instanceof Array){if("none"!=this.style.display&&(this.style.display="none"),t=x.model[e],r=b(this),x.repeats.hasOwnProperty(e)||(x.repeats[e]={}),n=document.createDocumentFragment(),o=Object.keys(x.repeats[e]),o.length>t.length)for(var i=t.length;it.length)for(var s=t.length;sjc6l%1Tji)ciL&AnjAIQO3P@eQ~{Zc zc%#!!COuPHvYt$0%`LTD6RP=;wR)zL@jV?nazc&OLOyj8VHR&0x&nnaoNgHuP#U($ z%(rLxsMQX%J;XpJlPsugM9RTPb$PByAL?lV0CzGb;8Spo9NZf1Uyh?u1BwayM~r-l*T2&=Tn?UOHSuT+Kb?Np@y6B=XdRqwv_5}7bh8?%&!{K}O^ffCX zj(&=IGBYRBn?rSK`4YDX4;$~9!Hlh}(vKRo{6H!q=$bx_?nEAumzP^dbk9VN3B7fb zbH{+PZ{SCx>=r(Hf%y1$%eHVZ42uSSd|Njhp0=yZ1_?Bz((ix}426&q^snFl_VO{oW$Fg3a4^9-7?H!R(w>Iw1o76T(}@_nW>g$rNt8TK$UnOdK|8( zF0o+>v4Vh%J;UT@Rbl_?t`L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E(oEJMNT zm!$v4I(o?>1lW>en-mX18k@=7<$`CAa)JA*^G+7)P;)vf^Il?5cX4JnmDD)1yDEC=VY0{LNGb_Y(32Uv!|qlHvo5opbJx{J z9_Y~lykm?mTXq-bf8UjTGqm5Cua8#iod1 z{SZwQ&G_g!?K8aeP-CptSGJrTzUe+|DNrREHFsJ+0bU`R5zyv9$Y zD-7fH0YW`@WiYx&u|SIAE=ABS!Y)W?q@qNHav*EGa~ z^J^$y;W+Z1kt|!UK^C7@qAbu`5z}ALoZ^)%fQCiTE%ZNMYk5z3kk)qJ{Wd}^_^L@(#*WFurUoyU;Fg)zib_3g{j2;n1y{YTFxZsw+QsQdjMi zOHU|CVHg1+ac_)lO;*Dc5o+K!tgS$w$mBVB?g^`cS6pKldQ6Z#HVmA_(L!zy2e))9 z;#(`GR2pD%QPjV|)+YpFEQQOond0DZ+RmQlOyc72tgO+-}v`k!K{CCXN(>OqQEzsXGE`u!emy^ z9j)nVeoPxnFauxW4Q=v{<*IZNKC6m{qRXHXmS%46F&tR?{Ze7U3o8w;!k|^Z ec-#1zy2*6Y4K-*P-!>Ue(*FQ)dR!b65C8y&VBhBe diff --git a/examples/build/templates/basic-example.tmpl b/examples/build/templates/basic-example.tmpl index 13231ec..d27295b 100644 --- a/examples/build/templates/basic-example.tmpl +++ b/examples/build/templates/basic-example.tmpl @@ -3,7 +3,7 @@
-
embedded example
+
embedded example
diff --git a/examples/build/templates/repeat-example.tmpl b/examples/build/templates/repeat-example.tmpl index 931b251..530dbb1 100644 --- a/examples/build/templates/repeat-example.tmpl +++ b/examples/build/templates/repeat-example.tmpl @@ -28,7 +28,7 @@
- Name: + Name:
Age: diff --git a/examples/index.html b/examples/index.html index f804848..0a7e109 100644 --- a/examples/index.html +++ b/examples/index.html @@ -21,7 +21,7 @@

Basic Example:

-
embedded example
+
embedded example
@@ -149,7 +149,7 @@

Repeat Example:

- Name: + Name:
Age: diff --git a/examples/js/murk.js b/examples/js/murk.js index 69d258f..637e48d 100644 --- a/examples/js/murk.js +++ b/examples/js/murk.js @@ -191,12 +191,11 @@ // as well as the current key being processed. it tries to be extremely // light by only doing reads, and saving writes until the end. function handleRepeat(key) { - var repeatModel, attrs, repeatElKeys, frag, processRepeats; + var repeatModel, repeatElKeys, frag, processRepeats; if (state.model[key] instanceof Array) { // hide our first elem, so we can use it later if (this.style.display != 'none') this.style.display = 'none'; repeatModel = state.model[key]; - attrs = attr(this); // we keep reference of all of our repeats // inside of state.repeats, so we always @@ -223,7 +222,7 @@ // processes each repeat individually processRepeats = function(repeat, i) { - var el, atts, $key = (key + '.$' + i), newEl = false; + var el, $key = (key + '.$' + i), newEl = false; // we make a new key, out of our current key // and setup any new elems that we might need @@ -239,14 +238,13 @@ // are fresh, and non object things // can be check simply like this if (el.innerHTML != repeatModel) { - atts = attr(el); // new els get sanitized if (newEl) { - atts(opts.selectorPrefix, 'rm'); - atts(opts.selectorPrefix + '-count', 'rm'); - atts(opts.selectorPrefix + '-bound', 'rm'); - atts(opts.selectorPrefix + '-repeat', $key); + delete el.dataset.murk; + delete el.dataset.murkCount; + delete el.dataset.murkBound; + el.dataset.murkRepeat = $key; } if (typeof repeat == 'object') { // allows us to keep ref of new $key, @@ -255,7 +253,7 @@ repeat.$key = $key; Array.prototype.forEach.call(el.getElementsByTagName('*'), processNodes, repeat); } else { - el.innerHTML = repeat; + setupTextNode(el, repeat); } // let their be light XD if (el.style.display == 'none') el.style.display = ''; @@ -273,26 +271,19 @@ // proccesses the filters added to any // given bound elem function processFiltersEvent(key) { - var attrs, filters, filterMutate, processFilter; - attrs = attr(this); - if (attrs) { - filters = attrs(opts.selectorPrefix + '-filter'); - filterMutate = attrs(opts.selectorPrefix + '-filter-mutate'); - if (filters) { - processFilter = function(filter) { - if (state.filters.hasOwnProperty(filter) && - state.model.hasOwnProperty(key)) { - var val = state.filters[filter].call(this, state.model[key]); - if (typeof val != 'undefined' && filterMutate) { - state.model[key] = val; - } - setupTextNode(this, val); - } - }; - if (filters.indexOf(',') != -1) filters = filters.split(','); - if (!(filters instanceof Array)) filters = [filters]; - Array.prototype.forEach.call(filters, processFilter, this); - } + var filters, processFilter; + if ('murkFilter' in this.dataset) { + filters = this.dataset.murkFilter; + processFilter = function(filter) { + if (state.filters.hasOwnProperty(filter) && + state.model.hasOwnProperty(key)) { + var val = state.filters[filter].call(this, state.model[key]); + setupTextNode(this, val); + } + }; + if (filters.indexOf(',') != -1) filters = filters.split(','); + if (!(filters instanceof Array)) filters = [filters]; + Array.prototype.forEach.call(filters, processFilter, this); } } @@ -325,9 +316,8 @@ // times we're interacting with our // elems function trackCountEvent() { - var count, attrs = attr(this); - count = attrs(opts.selectorPrefix + '-count'); - attrs(opts.selectorPrefix + '-count', (count ? parseInt(count,0)+1 : 1)); + var count = ('murkCount' in this.dataset ? this.dataset.murkCount : null); + this.dataset.murkCount = (count ? parseInt(count,0)+1 : 1); } // handles dom manipulation diff --git a/src/murk.js b/src/murk.js index 69d258f..637e48d 100644 --- a/src/murk.js +++ b/src/murk.js @@ -191,12 +191,11 @@ // as well as the current key being processed. it tries to be extremely // light by only doing reads, and saving writes until the end. function handleRepeat(key) { - var repeatModel, attrs, repeatElKeys, frag, processRepeats; + var repeatModel, repeatElKeys, frag, processRepeats; if (state.model[key] instanceof Array) { // hide our first elem, so we can use it later if (this.style.display != 'none') this.style.display = 'none'; repeatModel = state.model[key]; - attrs = attr(this); // we keep reference of all of our repeats // inside of state.repeats, so we always @@ -223,7 +222,7 @@ // processes each repeat individually processRepeats = function(repeat, i) { - var el, atts, $key = (key + '.$' + i), newEl = false; + var el, $key = (key + '.$' + i), newEl = false; // we make a new key, out of our current key // and setup any new elems that we might need @@ -239,14 +238,13 @@ // are fresh, and non object things // can be check simply like this if (el.innerHTML != repeatModel) { - atts = attr(el); // new els get sanitized if (newEl) { - atts(opts.selectorPrefix, 'rm'); - atts(opts.selectorPrefix + '-count', 'rm'); - atts(opts.selectorPrefix + '-bound', 'rm'); - atts(opts.selectorPrefix + '-repeat', $key); + delete el.dataset.murk; + delete el.dataset.murkCount; + delete el.dataset.murkBound; + el.dataset.murkRepeat = $key; } if (typeof repeat == 'object') { // allows us to keep ref of new $key, @@ -255,7 +253,7 @@ repeat.$key = $key; Array.prototype.forEach.call(el.getElementsByTagName('*'), processNodes, repeat); } else { - el.innerHTML = repeat; + setupTextNode(el, repeat); } // let their be light XD if (el.style.display == 'none') el.style.display = ''; @@ -273,26 +271,19 @@ // proccesses the filters added to any // given bound elem function processFiltersEvent(key) { - var attrs, filters, filterMutate, processFilter; - attrs = attr(this); - if (attrs) { - filters = attrs(opts.selectorPrefix + '-filter'); - filterMutate = attrs(opts.selectorPrefix + '-filter-mutate'); - if (filters) { - processFilter = function(filter) { - if (state.filters.hasOwnProperty(filter) && - state.model.hasOwnProperty(key)) { - var val = state.filters[filter].call(this, state.model[key]); - if (typeof val != 'undefined' && filterMutate) { - state.model[key] = val; - } - setupTextNode(this, val); - } - }; - if (filters.indexOf(',') != -1) filters = filters.split(','); - if (!(filters instanceof Array)) filters = [filters]; - Array.prototype.forEach.call(filters, processFilter, this); - } + var filters, processFilter; + if ('murkFilter' in this.dataset) { + filters = this.dataset.murkFilter; + processFilter = function(filter) { + if (state.filters.hasOwnProperty(filter) && + state.model.hasOwnProperty(key)) { + var val = state.filters[filter].call(this, state.model[key]); + setupTextNode(this, val); + } + }; + if (filters.indexOf(',') != -1) filters = filters.split(','); + if (!(filters instanceof Array)) filters = [filters]; + Array.prototype.forEach.call(filters, processFilter, this); } } @@ -325,9 +316,8 @@ // times we're interacting with our // elems function trackCountEvent() { - var count, attrs = attr(this); - count = attrs(opts.selectorPrefix + '-count'); - attrs(opts.selectorPrefix + '-count', (count ? parseInt(count,0)+1 : 1)); + var count = ('murkCount' in this.dataset ? this.dataset.murkCount : null); + this.dataset.murkCount = (count ? parseInt(count,0)+1 : 1); } // handles dom manipulation