Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
Make applying setters more lightweight
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Valls Fernández committed Aug 3, 2016
1 parent 16212c3 commit 69a1cd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
55 changes: 7 additions & 48 deletions apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ var Setter = require('y-setter'),
setters = Symbol(),
connections = Symbol(),
observer = Symbol(),
bubbleHandler = Symbol(),
captureHandler = Symbol(),

events = [
'input','change','submit','reset',
'keydown','keyup','keypress',
'click','mousedown','mouseup','mouseover','mouseout','mousemove',
'touchstart','touchend','touchmove','touchcancel',
'resize','focus','blur','scroll','load',
'animationstart','animationend','animationiteration','transitionend',
'digestion'
],
events = ['input','change','scroll'],
globalEvents = ['resize'],

getPair,cssAssign,watcher;

Expand Down Expand Up @@ -131,7 +123,7 @@ function onDestruction(){
function listener(){
var s = this.that[setters];
digest(s,this.that);
setTimeout(digest,0,s,this.that);
setTimeout(digest,50,s,this.that);
}

function digest(s,that){
Expand All @@ -148,20 +140,8 @@ function attach(that){
that: that
};

that[bubbleHandler] = {
handleEvent: listener,
that: that
};

for(i = 0;i < events.length;i++){
that.addEventListener(events[i],that[bubbleHandler],false);
that.addEventListener(events[i],that[captureHandler],true);
}

if(global.addEventListener) for(i = 0;i < events.length;i++){
global.addEventListener(events[i],that[bubbleHandler],false);
global.addEventListener(events[i],that[captureHandler],true);
}
for(i = 0;i < events.length;i++) that.addEventListener(events[i],that[captureHandler],true);
if(global.addEventListener) for(i = 0;i < globalEvents.length;i++) global.addEventListener(globalEvents[i],that[captureHandler],true);

if(global.MutationObserver && that instanceof global.Node){
bind = bind || listener.bind({that: that});
Expand All @@ -174,36 +154,15 @@ function attach(that){
subtree: true
});

if(global.document && global.document.body) that[observer].observe(document.body,{
childList: true,
attributes: true,
characterData: true,
subtree: true
});

if(global.document && global.document.head) that[observer].observe(document.body,{
childList: true,
attributes: true,
characterData: true,
subtree: true
});

}

}

function detach(that){
var i;

for(i = 0;i < events.length;i++){
that.removeEventListener(events[i],that[bubbleHandler],false);
that.removeEventListener(events[i],that[captureHandler],true);
}

if(global.removeEventListener) for(i = 0;i < events.length;i++){
global.removeEventListener(events[i],that[bubbleHandler],false);
global.removeEventListener(events[i],that[captureHandler],true);
}
for(i = 0;i < events.length;i++) that.removeEventListener(events[i],that[captureHandler],true);
if(global.removeEventListener) for(i = 0;i < globalEvents.length;i++) global.removeEventListener(globalEvents[i],that[captureHandler],true);

if(that[observer]){
that[observer].disconnect();
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
node:
version: 6.2.0
version: 6.3.1
dependencies:
pre:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
Expand Down

0 comments on commit 69a1cd3

Please sign in to comment.