Skip to content

Instantly share code, notes, and snippets.

@phillipskevin
Last active May 8, 2019 21:53
Show Gist options
  • Save phillipskevin/70859ac5b9235489b3489428577fbf70 to your computer and use it in GitHub Desktop.
Save phillipskevin/70859ac5b9235489b3489428577fbf70 to your computer and use it in GitHub Desktop.
can-observe/make-prototype with stache
<!doctype html>
<button>-</button>
<script src="./node_modules/steal/steal.js" main></script>
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;
});
{
"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 <kevin@bitovi.com>",
"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