@replygirl/proxyable-behavior-subject
v0.2.2
Published
BehaviorSubject that returns a Proxy
Downloads
1
Readme
ProxyableBehaviorSubject
A BehaviorSubject
that returns a Proxy
. All the reactivity, without having to call next
!
Note: I literally haven't tested this
Installation
yarn add @replygirl/proxyable-behavior-subject
Usage
import ProxyableBehaviorSubject from '@replygirl/proxyable-behavior-subject'
const foo = new ProxyableBehaviorSubject({ bar: true })
const f = foo.proxy
console.info(f.bar, foo.value.bar) // true, true
// set with the proxy and the value will stay in sync
f.bar = true
console.info(f.bar, foo.value.bar) // true, true
// call next as usual and the proxy will stay in sync
foo.next({ bar: false })
console.info(f.bar, foo.value.bar) // false, false
// use the p alias to skip assignment
foo.p.bar = true
console.info(foo.p.bar, foo.value.bar) // true, true