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

Declaratively subscribe method proposal... #1

Open
michaeldanielbell opened this issue Mar 6, 2018 · 11 comments
Open

Declaratively subscribe method proposal... #1

michaeldanielbell opened this issue Mar 6, 2018 · 11 comments

Comments

@michaeldanielbell
Copy link

What do you think about having a subscribe method that accepts a callback. Maybe even a parameter to specify what it should listen to. Could be a nice way to declaratively use in re:dom.

i.e

const listener = store.subscribe('a.b', (callback) => {
     console.log(`Magic callback data: ${callback}`)
})

//if needed
listener.unsubscribe();

What do you think?

@michaeldanielbell michaeldanielbell changed the title Just a thought Declaratively subscribe method proposal... Mar 6, 2018
@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

The problem with subscribes is, that if you forget to unsubscribe or there's a bug skipping unsubscribe, you'll get memory leaks really easily..

@michaeldanielbell
Copy link
Author

Fair enough.
Just out of interest, do you use re:dom store in some kind of declarative way.
i.e By way of updating the store and then having those changes populate through your app?

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

I usually have a separate client-side API, which I use to change the app state. Then I'll do a single update for the whole app in a requestAnimationFrame throttle so that there's only one update per animation frame.

In addition to that, there might be some separate temporary component state, but I try to avoid that.

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

I should create an example app with RE:DOM to show how I personally use RE:DOM 😎

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

Currently I don't actually even use redom-store, I tend to just:

state = {
  ...state,
  changedProperty: changedValue
}

😄

@michaeldanielbell
Copy link
Author

How are you passing that state data to your various components?

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

With view.update(state)

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

and list.update(items), and router.update(route, state), and place(visible, state) 😎

@michaeldanielbell
Copy link
Author

Yes, make sense.
But I guess I mean, since your passing state around to various parts of your app. It seems like a bit of a manual process, to update all your views, that use the same state.

Thats what I was thinking with some kind of redux like subscribe
So component data stays in sync with state

@michaeldanielbell
Copy link
Author

Perhaps an example of how you use state with re:dom would be good :)

@pakastin
Copy link
Member

pakastin commented Mar 6, 2018

agreed 😅

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