git ssb

1+

Matt McKegg / mutant



Commit dacc7137a972984d5f5adfe48e91c35b8056adb9

lazy-watcher: allow use with prototypes

Matt McKegg committed on 10/6/2016, 4:24:27 AM
Parent: 97b585dee0f210742bd323dea327d09701a333d6

Files changed

lib/lazy-watcher.jschanged
lib/lazy-watcher.jsView
@@ -1,6 +1,7 @@
11 module.exports = function (update, onBind, onUnbind) {
22 var lazy = false
3+ var context = this
34
45 var obj = {
56 live: false,
67 suspended: false,
@@ -17,22 +18,22 @@
1718 obj.broadcast()
1819 },
1920
2021 onUpdate: function () {
21- if (update()) {
22+ if (update.apply(context)) {
2223 broadcast()
2324 }
2425 },
2526
2627 checkUpdated: function () {
2728 if (!obj.live || lazy) {
2829 lazy = false
29- update()
30+ update.apply(context)
3031 }
3132 },
3233
3334 getValue: function () {
34- obj.checkUpdated()
35+ obj.checkUpdated.apply(context)
3536 return obj.value
3637 },
3738
3839 addListener: function (listener) {
@@ -44,9 +45,9 @@
4445
4546 if (!obj.live) {
4647 obj.live = true
4748 lazy = true
48- onBind()
49+ onBind.apply(context)
4950 }
5051
5152 return function release () {
5253 for (var i = 0, len = obj.listeners.length; i < len; i++) {
@@ -56,9 +57,9 @@
5657 }
5758 }
5859 if (!obj.listeners.length && obj.live) {
5960 obj.live = false
60- onUnbind()
61+ onUnbind.apply(context)
6162 }
6263 }
6364 }
6465 }

Built with git-ssb-web