Skip to content

Fix data functions being called twice. (fix #2687) #2689

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

Merged
merged 1 commit into from
Apr 18, 2016

Conversation

blake-newman
Copy link
Member

@blake-newman blake-newman commented Apr 18, 2016

  • Added test for checking prop to data clash
  • Added test to ensure data function is only called once per strut
  • Removed this._runtimeData uses 'data' for prop to data clash check

Fixes: ISSUE-2687

@blake-newman
Copy link
Member Author

@vuejs/collaborators Anyone with any opinions why this._runtimeData is used...

@kazupon
Copy link
Member

kazupon commented Apr 18, 2016

@blake-newman
I think that this commit will probably be a good reference for that. 😺

@blake-newman
Copy link
Member Author

blake-newman commented Apr 18, 2016

@kazupon so i guess i can remove my test for the warnings... However tests pass fine if not using _runtimeData

Seems slightly flawed for recalling data function for warning on dev, as could incur different results in production/development. However, this no longer acts as so in current code, so it's a matter of what this._runtimeData achieves.

- Added test for checking prop to data clash
- Added test to ensure data function is only called once per strut
- Removed this._runtimeData uses 'data' for prop to data clash check
@yyx990803 yyx990803 changed the title [Fix] [ISSUE-2687] Fix data functions being called twice. Fix data functions being called twice. (fix #2687) Apr 18, 2016
@yyx990803 yyx990803 merged commit 25c8476 into vuejs:dev Apr 18, 2016
@dargue3
Copy link

dargue3 commented Apr 18, 2016

Hey, I have been asking about this question on various sites trying to find why my data() hook is being duplicated... so according to this it's a bug introduced starting at 1.0.18 and the newest commit is fixing? Is data() supposed to fire twice? Just checking for my own sanity :)

@posva
Copy link
Member

posva commented Apr 18, 2016

@dargue3 No, it's not. It should only be fired once 😄

@dargue3
Copy link

dargue3 commented Apr 18, 2016

@posva well at least I know I'm not crazy. Interesting how it has taken this long for anyone to notice... Or am I just the only one sending AJAX requests in my data() hook?

Like I said, through trial-and-error I found that this bug was introduced in v1.0.18

@posva
Copy link
Member

posva commented Apr 18, 2016

@dargue3 You might not be the only one but you shouldn't do that 😖
This may help you http://vuejs.org/guide/components.html#activate-Hook

Thanks for reporting that @dargue3

@yyx990803
Copy link
Member

This was partially a dirty workaround to allow passing values for props in the data option. But now I think it was a bad idea to overload data for that purpose.

So now I've introduced a dedicated option propsData for passing props at instantiation calls.

@YerkoPalma
Copy link

I don't understand the purpose of the new propsData hook. The props can be defined with a default value, and data can be initialized in the data() hook right?

@azamat-sharapov
Copy link

@YerkoPalma props are resolved async, as described here and I think propsData is sync, so it's ready in child component init. But let's wait until Evan updates docs about new propsData, he will make it clear.

@yyx990803
Copy link
Member

yyx990803 commented Apr 18, 2016

@YerkoPalma default values are the same for every instance created. propsData is a way to provide different prop values at instance creation time without having to wrap it in a parent instance.

e.g. instead of first registering and rendering a parent instance with:

<test :data="123"></test>

You can just

new Test({
  propsData: {
    data: 123
  }
})

This is mostly about facilitating easier unit tests for components, not something you'd use very often in application code.

@YerkoPalma
Copy link

I see. Everything that help on tests is fine 😄 Thanks for the answer.

@blake-newman
Copy link
Member Author

👍 makes sense

@audinue
Copy link

audinue commented Apr 18, 2016

That was fast 👍

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

Successfully merging this pull request may close these issues.

8 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy