Skip to content

Instantly share code, notes, and snippets.

@phillipskevin
Last active February 7, 2018 20:37
Show Gist options
  • Save phillipskevin/f82b2b22d0664f4a484de65afa3bd824 to your computer and use it in GitHub Desktop.
Save phillipskevin/f82b2b22d0664f4a484de65afa3bd824 to your computer and use it in GitHub Desktop.
can-view-live memory leak
<!doctype html>
<script src="./node_modules/steal/steal.js"></script>
import nodeLists from "can-view-nodelist";
import DefineMap from "can-define/map/map";
import DefineList from "can-define/list/list";
import stache from "can-stache";
import "can-stache-bindings";
var origRegister = nodeLists.register;
nodeLists.register = function (nodeList, unregistered, parent, directlyNested) {
if (parent.replacements && parent.replacements.length) {
console.log(parent.replacements);
}
origRegister.apply(this, arguments);
};
var VM = DefineMap.extend({
list: {
Type: DefineList,
value() {
return new DefineList([1, 2]);
}
},
addItem() {
this.list.push(this.list.length + 1);
},
removeItem() {
this.list.splice(0, 1);
}
});
var vm = new VM();
var template = stache(`
<ul>
{{#each list}}
<li>{{this}}</li>
{{/each}}
</ul>
<button on:click="addItem()">Add an item</button>
<button on:click="removeItem()">Remove an item</button>
`);
var frag = template(vm);
document.body.appendChild(frag);
{
"name": "f82b2b22d0664f4a484de65afa3bd824",
"version": "1.0.0",
"description": "https://jsbin.com/noloqox/edit?js,output in a gist",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/f82b2b22d0664f4a484de65afa3bd824.git"
},
"keywords": [],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/f82b2b22d0664f4a484de65afa3bd824"
},
"homepage": "https://gist.github.com/f82b2b22d0664f4a484de65afa3bd824",
"dependencies": {
"can-define": "^1.5.5",
"can-stache": "^3.14.11",
"can-stache-bindings": "^3.11.10",
"can-view-nodelist": "^3.1.1",
"steal": "^1.6.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment