git ssb

1+

Matt McKegg / mutant



Commit 4cc5d7c35493700dc9a40f3cb6da6a2b6e3ce7dc

when: resolve inner observs if root is not observable

Matt McKegg committed on 7/15/2016, 4:42:04 AM
Parent: 1964140bd2d8f29be42fb1ff7af768d7fb89ef59

Files changed

when.jschanged
when.jsView
@@ -1,11 +1,29 @@
11 var computed = require('./computed')
2 +var isObservable = require('./is-observable')
23
34 module.exports = When
45
56 function When (obs, ifTrue, ifFalse) {
7 + ifTrue = handleInnerValues(ifTrue)
8 + ifFalse = handleInnerValues(ifFalse)
69 return computed([obs, ifTrue, ifFalse], lambda)
710 }
811
912 function lambda (value, ifTrue, ifFalse) {
1013 return value ? ifTrue : ifFalse
1114 }
15 +
16 +function handleInnerValues (obs) {
17 + if (Array.isArray(obs) && obs.some(isObservable)) {
18 + // HACK: resolve inner observs
19 + var inner = []
20 + return computed(obs, function () {
21 + for (var i = 0; i < arguments.length; i++) {
22 + inner[i] = arguments[i]
23 + }
24 + inner.length = arguments.length
25 + return inner
26 + })
27 + }
28 + return obs
29 +}

Built with git-ssb-web