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

v2: automatically calling functions in component trees #840

Closed
jaeh opened this issue May 16, 2019 · 3 comments
Closed

v2: automatically calling functions in component trees #840

jaeh opened this issue May 16, 2019 · 3 comments

Comments

@jaeh
Copy link
Contributor

jaeh commented May 16, 2019

in v1 i could do:

const component = () => OtherComponent

and it would execute my OtherComponent function with (state, actions) as arguments.

maybe v2 should call this function (maybe even with empty props object)?

OtherComponent({})

also, kinda related, there is no passing down full state to components anymore, is there?

@jorgebucaran
Copy link
Owner

@jaeh I think you're referring to what in the V1 documentation we used to call "lazy components". V2 has a different, unrelated feature called "lazy views" or just lazy, see #606.

also, kinda related, there is no passing down full state to components anymore, is there?

Correct. This is not in V2.

@jaeh
Copy link
Contributor Author

jaeh commented May 18, 2019

hm, i am almost done with the rewrite, only one blocking issue left:

i have the Pre module, which does syntax highlighting, and it has a global theme shared between all Pre's.

i used to set the global state.pre.theme value and access it in the Pre component without the user of the module declaring the state explicitly eg:

Pre('some_javascript_code()')

which i would expand internally to:

Pre({ content: 'some_code()', theme: state.pre.theme })

looking through the codebase i see no way to add a StateProvider component (pseudocode)

export const StateProvider = state => (node, props, children) => h(node, { ...state, ...props }, children)

(Without initializing it in app.render to get the state, which would be a pretty ugly hack)

but, looking at subscriptions code, i see that they get the state passed to

batch(subscriptions(state))

am i correct that this would be my way to subscribe to state changes?

@jaeh
Copy link
Contributor Author

jaeh commented May 18, 2019

actually, thinking about this a bit more,
i can write a StateProvider component in userland and pass the state to it in my view function. will try that now :)

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