ds300 / derivablejs

Functional Reactive State for JavaScript and TypeScript
Apache License 2.0
515 stars 23 forks source link

lens/proxy doesn't react when changed #69

Closed fiatjaf closed 7 years ago

fiatjaf commented 7 years ago
const {proxy} = require('derivable')

var back = []

let front = proxy({
  get () { return back[0] },
  set (v) { back.unshift(v) }
})

front.react(f => console.log('FRONT:', f))

front.set(12)
front.set('bababa')
front.set(77778)

Shouldn't this code print FRONT: undefined, FRONT: 12, FRONT: bababa and FRONT: 77778? It only prints FRONT: undefined.

The same code using a raw atom instead of a proxy produces the expected output.

(Using 2.0.0-beta.0)

ds300 commented 7 years ago

back needs to be an atom. Proxies are only like bi-directional derivations.

On 27 Jul 2017 7:25 pm, "Giovanni T. Parra" notifications@github.com wrote:

const {proxy} = require('derivable') var back = [] let front = proxy({ get () { return back[0] }, set (v) { back.unshift(v) } }) front.react(f => console.log('FRONT:', f)) front.set(12)front.set('bababa')front.set(77778)

Shouldn't this code print FRONT: undefined, FRONT: 12, FRONT: bababa and FRONT: 77778? It only prints FRONT: undefined.

(Using 2.0.0-beta.0)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ds300/derivablejs/issues/69, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL1qUzPw-ZsF75HRPheA5iUVMmGs7B4ks5sSNYTgaJpZM4Olqbv .

fiatjaf commented 7 years ago

Thank you.