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

Helper functions no longer visible in oncreate #1129

Closed
bwbroersma opened this issue Jan 25, 2018 · 2 comments
Closed

Helper functions no longer visible in oncreate #1129

bwbroersma opened this issue Jan 25, 2018 · 2 comments

Comments

@bwbroersma
Copy link
Contributor

bwbroersma commented Jan 25, 2018

So since issue #1079 helper functions are no longer visible in the oncreate, and this is by design right? So if I have a helper function that does nothing with my state (e.g. a => a + 1) I should make it an method or move it outside my svelte component and then reference it again in the helpers section if I also need this function in my template? Just checking if I understand it right, I think it would be nice to use helpers in the oncreate, I use this for some api resolving that is also used in the template for an Oauth link.

See this is working in REPL 1.51.1 and failing in REPL 1.52.0.

@Conduitry
Copy link
Member

Yep this is by design. Helper functions should always be pure (not depend on the state, not affect the state) and are intended for use in the template. The intent is that methods should have some sort of side-effect, so the preferred way to handle what you want is to move the function outside your component (you don't need to move it completely outside the file, just out of the main export default { ... }) and refer to it wherever you need it and also include it in your helpers.

I do see #1079 as definitely more of a leaky scope bug rather than a feature - the javascript in your <script> tag should be 'just javascript', with no special extra globals available to it.

@bwbroersma
Copy link
Contributor Author

@Conduitry thanks, I will have to move some code then, since I was using/abusing this leaky scope bug.

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