Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[section] start #57

Open
yoshuawuyts opened this issue Feb 11, 2017 · 9 comments
Open

[section] start #57

yoshuawuyts opened this issue Feb 11, 2017 · 9 comments

Comments

@yoshuawuyts
Copy link
Member

  • describe how subscriptions work
  • describe the "global start" pattern; e.g. wait until multiple models have booted before changing some other variable (e.g. "application has now loaded, stop rendering the placeholder view")
@dannief
Copy link

dannief commented May 8, 2017

@yoshuawuyts Until the docs get updated to describe the subscriptions model, any way you can point to some samples or source code to that describes how they work?

@bcomnes
Copy link
Collaborator

bcomnes commented May 8, 2017

@dannief sounds like maybe you are trying to use an older Choo release? The newest version of Choo does away with those and only uses mutable state objects and an event emitter. These are described in detail in https://handbook.choo.io

Or are you looking specifically for older docs for an existing project?

@dannief
Copy link

dannief commented May 8, 2017

@yoshuawuyts @bcomnes I actually read the docs, so I am aware of the API change. I think I may have misunderstood something that was written at the end of the handbook, implying more documentation to come.

So there is no way to subscribe to state changes then? Say you want to perform some logic on certain state changes like syncing with local storage?

I know you can subscribe all events using the "*". So if I wanted to know if a particular state change was made, I'd have to manually do a diff with the current state?

@bcomnes
Copy link
Collaborator

bcomnes commented May 8, 2017

That would work (e.g. listening on all events and checking if state has changed), or you can emit another event whenever you know you are changing state.

Here is an example of how an app I'm working on handles state updates from an external source:

https://github.com/hypermodules/hyperamp/blob/master/renderer/stores/player.js

I'm not sure that helps. If it does, please note what helped clarify the confusion so we can maybe add that to the docs.

@bcomnes
Copy link
Collaborator

bcomnes commented May 8, 2017

I guess the way I think about it, rather than listen for state updates, listen for the events that will cause state to update if you need to hook in there. Otherwise, update state as you go, and emit render whenever you want a fresh repaint of the page.

@dannief
Copy link

dannief commented May 8, 2017

@bcomnes Thanks for clarification, I see how your suggestions would work. I can either just listen for events that I know update the state changes I need to act on, or for all the handlers that change the state, I can emit another event and listen for that.

That certainly works. I suppose I was checking if there was a more direct way. However, I understand wanting keeping the API nice I small.

Nice work on version 5 btw, I really like the simplicity.

@bcomnes
Copy link
Collaborator

bcomnes commented May 8, 2017

A wild v6 appears! choojs/choo#489 (API is nearly the same though).

Yeah, I'm digging the changes too!

@bcomnes
Copy link
Collaborator

bcomnes commented May 8, 2017

@dannief I had an idea... Rather than set state directly on the state object, you could write a function that sets state for you, both on Choo state and wherever else you need it to (localstorage)? When you set state with that, you don't run the risk of forgetting to set it in two places. That way the two (or 3 or 4...) are always in sync.

You can also link into page lifecycle events and dump state into local storage when the page closes or navigates away if thats the goal.

@dannief
Copy link

dannief commented May 8, 2017

@bcomnes That's a good idea re the function. I was thinking about something along those lines as well
Linking into the page life-cycle was something I hadn't though of. I have to try that. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants