Last active
May 8, 2019 21:53
-
-
Save phillipskevin/70859ac5b9235489b3489428577fbf70 to your computer and use it in GitHub Desktop.
can-observe/make-prototype with stache
This file contains 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> | |
<button>-</button> | |
<script src="./node_modules/steal/steal.js" main></script> |
This file contains 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 makePrototype from "can-observe/src/-make-prototype"; | |
import stache from "can-stache"; | |
function Obj(num) { | |
this.num = num; | |
}; | |
Obj.prototype = makePrototype.observable(Object.create({}), { | |
observe: makePrototype.observable | |
}); | |
const obj = new Obj(5); | |
const renderer = stache("<p>{{num}}</p>"); | |
const frag = renderer(obj); | |
document.body.appendChild(frag); | |
const button = document.querySelector("button"); | |
button.addEventListener("click", () => { | |
obj.num = obj.num - 1; | |
}); |
This file contains 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": "can-observe-prototype-with-stache", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "Kevin Phillips <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"can-observe": "^2.3.0", | |
"can-stache": "^4.17.15", | |
"steal": "^2.2.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment