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

Passing arguments to init #1082

Closed
kofifus opened this issue Feb 1, 2022 · 4 comments
Closed

Passing arguments to init #1082

kofifus opened this issue Feb 1, 2022 · 4 comments

Comments

@kofifus
Copy link
Contributor

kofifus commented Feb 1, 2022

In the second example here
https://github.com/jorgebucaran/hyperapp/blob/main/docs/api/app.md#init

app({
  // ...
  init: (problems = 99) => [
    { loading: true }, 
    butASPAAintOne(problems)
  ],
})

I am not clear how would one pass an argument (problems) to Init ? I cannot find anything in the docs

If there is no way to pass a different problems to the default wouldn't it be better to do:

app({
  // ...
  init: [
    { problems: 99, loading: true }, 
    butASPAAintOne(problems)
  ],
})

Also on the same page it says init is required 100% but later says "Note that if you leave init: undefined the state will be set to an empty object ({}) by default" so I think one of these is wrong ?

?

@zaceno
Copy link
Contributor

zaceno commented Feb 2, 2022

Yes this is certainly an error. It still works because init behaves like an action but the state will be undefined. So problems will be set to 99, for use in the effect. But there is no reason why an example in the docs should be so confusing

@jorgebucaran
Copy link
Owner

You can't pass arguments to Hyperapp's init function. That's simply a way to create a variable with a default value without const/let. It should be noted, though.

@kofifus
Copy link
Contributor Author

kofifus commented Feb 4, 2022

OK I hope the docs can be amended there

@kofifus kofifus closed this as completed Feb 4, 2022
@jorgebucaran
Copy link
Owner

If you see closely, your suggestion is actually a runtime error.

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