question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access an immutable version of state via subscribers

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
toddselfcommented, Jun 19, 2016

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.

1reaction
yoshuawuytscommented, Jun 19, 2016

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found