UNPKG

mutant

Version:

Create observables and map them to DOM elements. Massively inspired by hyperscript and observ-*. No virtual dom, just direct observable bindings. Unnecessary garbage collection is avoided by using mutable objects instead of blasting immutable junk all ove

65 lines (52 loc) 1.37 kB
var test = require('tape') require('source-map-support').install() // currently only these types support onListen/unlisten // in the future, all types should allow it! var types = [ function array (opts) { return require('../array')([], opts) }, function dict (opts) { return require('../dict')({}, opts) }, function map (opts) { return require('../map')([], () => {}, opts) }, function computed (opts) { return require('../computed')({}, () => {}, opts) } ] types.forEach(ctor => { test(`${ctor.name} - onListen / onUnlisten`, t => { var onListenCount = 0 var onUnlistenCount = 0 var onListenReleaseCount = 0 var obs = ctor({ onListen: () => { onListenCount += 1 return () => { onListenReleaseCount += 1 } }, onUnlisten: () => { onUnlistenCount += 1 } }) t.equal(onListenCount, 0) var unlisten1 = obs(() => {}) t.equal(onListenCount, 1) var unlisten2 = obs(() => {}) t.equal(onListenCount, 1) // should still be 1 unlisten1() t.equal(onUnlistenCount, 0) unlisten2() t.equal(onUnlistenCount, 1) t.equal(onListenReleaseCount, 1) var unlisten3 = obs(() => {}) t.equal(onListenCount, 2) unlisten3() t.equal(onUnlistenCount, 2) t.equal(onListenReleaseCount, 2) t.end() }) })