Comments (6)
Alternatively:
const extract$: Observable<{a: A, c: C}> = store.extract({
a: state => state.a,
c: state => state.b.c
})
from lenrix.
The second version is less type-safe, but more concise. Both alternatives are viable.
from lenrix.
The second version (state selectors) would also support:
const extract$: Observable<{a: A, c: C}> = store.extract({
a: state => store.lens.focusOn('a').read(state),
c: state => store.lens.focusOn('b').focusOn('c').read(state)
})
Which is quite verbose. However, if the read()
function was properly bound to the lens, we could do:
const extract$: Observable<{a: A, c: C}> = store.extract({
a: store.lens.focusOn('a').read,
c: store.lens.focusOn('b').focusOn('c').read
})
Which is way more concise. Anyway, it appears that binding functions to the lens would be most useful in many cases.
from lenrix.
Binding reading functions to lenses is now an issue in immutable-lens:
couzic/immutable-lens#2
from lenrix.
Due to TypeScript compilator type inference limitations, the version with selectors would actually look like:
const extract$: Observable<{a: A, c: C}> = store.extract({
a: (state: State) => state.a,
c: (state: State) => state.b.c
})
Which is not ideal either. Maybe another version using lenses should be considered:
const extract$: Observable<{a: A, c: C}> = store.extract({
a: store.lens.focusOn('a'),
c: store.lens.focusOn('b').focusOn('c')
})
from lenrix.
Finally, extract()
accepts both selectors and lenses
from lenrix.
Related Issues (20)
- Make logger configurable on store instances
- Logger global shutdown switch
- updatable fields VS readonly fields
- Enable custom change detection strategy
- computeFromField() & computeFromField$()
- webpack hot module reload support HOT 1
- Pass updatable state fields down focused store as readonly fields
- Remove all references to currentComputedState and computedState$
- Write tests that verify errors are correctly logged
- Catch and log errors that occur when computing values
- private VS public actions
- .updates(): allow a handler to return null or false to prevent a state update
- Can't .pluck() optional field
- Implement defaultValues()
- Implement `rejectNilFields()`
- document onActivate() and activate()
- Optimization (read-only values): store output state in data$ to prevent re-constructing it every time
- Delete onLoad()
- Type safety: computeFromField(nullable) returns non-nullable
- computeFromPath()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lenrix.