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

How to keep dom elements when state change? #133

Closed
yudao opened this issue Jul 6, 2016 · 4 comments
Closed

How to keep dom elements when state change? #133

yudao opened this issue Jul 6, 2016 · 4 comments

Comments

@yudao
Copy link

yudao commented Jul 6, 2016

Hi,
I'm creating a status list for my ops cron tasks.
I'm trying Choo with Brunch.io and http://materializecss.com/ for the look and feel.
All is working perfectly but I'm facing off a problem with states.

I have a state model called jobs which get information by API. I've created a subscription to request jobs every 5 seconds like this:

subscriptions: [
  (send) => setInterval(() => send('jobs:retrieve'), 5000)
],
reducers: {
    get: (action, state) => ({ nodes: state.jobs = action.payload })
},
effects: {
  retrieve: (action, state, send) => getAll(send)
}
// getAll make the request and perform a send('jobs:get', { payload: response }) action

Then, in a view when I click on a button I'm opening a modal bottom sheet:

<a class="task-add btn-floating btn-large waves-effect waves-light red" onclick=${e => $('#modal-task-zone').openModal()}>
  <i class="material-icons">add</i>
</a>

But when the subscriptions event is performed on my jobs state, my modal bottom sheet disappear.

So is there a way to keep my modal opened even on change state?

Thanks a lot,
Yu.

@yoshuawuyts
Copy link
Member

Umm, here's a modal component that works with yo-yo - https://github.com/shama/modal-element/tree/yo-yo; I know shama was smart in how he built it - perhaps it can work as an inspiration on how to tackle this. Cheers!

@yudao
Copy link
Author

yudao commented Jul 7, 2016

Ok thanks for the link I'll go to take a look. But there is no way to update only some views on state change ? or tell to the view to change or not change if a specific model thanks to his namespace has changed?. In fact, only my job-list-view.js must change when the request is done, the others should not.
Thanks a lot.
Yu.

@yoshuawuyts
Copy link
Member

@yudao under the hood there's a smart algorithm which updates the DOM tree efficiently; we take the DOM tree, and apply a set of patches to the DOM itself. You don't have to worry about optimizing the lists at this point; we do that for you - so just update the whole thing, and you should be sweet.

I wouldn't worry about perf until you run into any issues, and even then there are plenty of tricks to optimize. Cheers!

@yudao
Copy link
Author

yudao commented Jul 7, 2016

Yes and this is why I love choo!
Thanks a lot.
Yu.

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

2 participants