Last active
February 6, 2018 22:26
-
-
Save phillipskevin/b60894c9b607221c26b60e06d3974444 to your computer and use it in GitHub Desktop.
onteardown-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<script src="./node_modules/steal/steal.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Observation from "can-observation"; | |
import singleReference from "can-util/js/single-reference/single-reference"; | |
import canReflect from "can-reflect"; | |
import canSymbol from "can-symbol"; | |
import canEvent from "can-event"; | |
var getValueSymbol = "can.getValue"; | |
var onValueSymbol = "can.onValue"; | |
var offValueSymbol = "can.offValue"; | |
var noop = function() {}; | |
var event = "click"; | |
var el = document.createElement('div'); | |
var get = function() { return "hello"; }; | |
var obs = new Observation(get); | |
obs[canSymbol.for(getValueSymbol)] = get; | |
obs[canSymbol.for(onValueSymbol)] = function(updater) { | |
var translationHandler = function() { | |
updater(get()); | |
}; | |
singleReference.set(updater, this, translationHandler); | |
if (event === "radiochange") { | |
canEvent.on.call(el, "change", translationHandler); | |
} | |
canEvent.on.call(el, event, translationHandler); | |
}; | |
obs[canSymbol.for(offValueSymbol)] = function(updater) { | |
var translationHandler = singleReference.getAndDelete(updater, this); | |
if (event === "radiochange") { | |
canEvent.off.call(el, "change", translationHandler); | |
} | |
canEvent.off.call(el, event, translationHandler); | |
}; | |
var unbindUpdate = function(observable, updater) { | |
if(observable && observable[canSymbol.for(getValueSymbol)] && typeof updater === "function") { | |
canReflect.offValue(observable, updater); | |
} | |
}; | |
unbindUpdate(obs, noop); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "single-ref-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"can-event": "^3.7.6", | |
"can-observation": "^3.3.6", | |
"can-reflect": "^1.13.2", | |
"can-symbol": "^1.6.0", | |
"can-util": "^3.11.2", | |
"steal": "^1.6.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment