Access an immutable version of state via subscribers
See original GitHub issueI mentioned this on irc earlier today. On-demand, synchronous access to the data in the state isn’t 100% necessary in probably 99% of use-cases, but it does make it easier to work with a choo component from the outside.
Example: if someone wanted to access part of the state object (i.e. the data driving a boxcar view) in order to serialize it somewhere else:
const emitter = require('events')()
const app = choo()
app.model({
state: {
data: [],
moreState: [].
evenMore: {}
},
subscriptions: [
(send, state) => emitter.on('getData', (cb) => cb(null, state.data)
]
})
return emitter
Then someone could do:
boxcar.emit('getData', (err, data) => serializeData(data))
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Understanding Immutable State with Immutable.js and ...
Immutable state means its value cannot be changed once it's created. ... transactions aren't confirmed when customers pay for the product”.
Read more >Creating an Immutable, Asynchronous State Holder in C#
Once the state change transaction is complete, the new state is sent on a BehaviorSubject, which allows subscribers to be notified of the...
Read more >Using Immer with React: a Simple Solutions for Immutable ...
In React, using an Immutable state enables quick and cheap comparison of the state tree before and after a change.
Read more >Immutability in C# - CODE Magazine
The ImmutableArray property resolves the problem with collection and array-based properties. System.Collections.Immutable contains immutable ...
Read more >Configure immutability policies for blob versions - Azure Storage
Navigate to the desired container. · Select the More button on the right, then select Access policy. · Under Immutable blob storage, select...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I gave this some more thought last night. It’s a pain to not be able to access state ever, but it’s for the better. It just means if I want some sort of serialization I’m going to have to create it as an option, which keeps things MUCH neater as it is.
I feel this might conflict with https://github.com/yoshuawuyts/choo/issues/32; if not programmatically, definitely in the mental model. Perhaps what could be an option is to expose send-action under the hood as
app._send
/app._getState()
or something for the 1% of the time people are interested in this - don’t even feel it’s needed to document, as it def should be avoided generally. Would that work for you?