cyclejs-community / one-fits-all

The one-fits-all flavor for create-cycle-app
MIT License
34 stars 8 forks source link

Question about route Component scope #92

Closed zheeeng closed 6 years ago

zheeeng commented 6 years ago

I try to remove the scope config in the src/routes.ts, or rename scopes, this initial demo doesn't work anymore. Why is this 'scope' required for running app? I did the corresponding modifications in src/components/app.tsx isolate calling.

jvanbruegge commented 6 years ago

what exactly did you modify in app.tsx?

zheeeng commented 6 years ago

This modification seems break the storing state locally, after routing to another component the inputs' values are read from previous values randomly.

// /src/components/app.tsx

    const componentSinks$ = match$.map(
-       ({ path, value: { component, scope } }) => {
+       ({ path, value: { component } }) => {
-           return isolate(component, scope)({
+           return isolate(component)({
                ...sources,
                router: sources.router.path(path)
            })
        }
    )

In a reality project, removing scope sometimes cause my app stuck after interaction with this app a while, it is hard to make mimal reproduction.

jvanbruegge commented 6 years ago

calling isolate without scope argument is not recommended, because it generates a random scope every time it gets called. For your case that means that every time you navigate, you get a new key to store the state under it. In general, we recommend to supply an explicit scope.

zheeeng commented 6 years ago

I thought that exporting the isolated component is of a best practice before, like below: https://github.com/cyclejs/cyclejs/blob/master/examples/advanced/bmi-nested/src/LabeledSlider.js

So I want to use isolate without maintaining the scope names.

jvanbruegge commented 6 years ago

But then, dont isolate it again. The problem with your code is that it isolates it again on every route change

zheeeng commented 6 years ago

Thx for your suggestion.