Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor: remove unnecessary checks (#7875)"
This reverts commit 43551b4.
- Loading branch information
903be9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a f$%@y (friendly) man decided to 'remove unnececssary checks'?
typeof data === 'function' is assumes that data must be a function SO it can't be undefined, if you remove these checks instead of default data value {}, original undefined can be bassed, or even worse, you stick to pass data with a function only and excludes passing something else. You can, but your code will end up with getData(undefined, vm).
903be9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are a few examples:
First:
This is what we expect.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dividing line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Second:
This is because the
data
option of the child component must be a function. If it is not a function then thestrats.data
function will returnparentVal(Vue.options.data)
, but sinceVue.options.data
is equal toundefined
, the value ofChild.options.data
is alsoundefined
.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dividing line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Third:
According to the second example, the value of
Child.options.data
isundefined
.So at this pointnew Child()
is equivalent tonew Vue()
, so the value ofcins.$options.data
is themergedInstanceDataFn
function.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dividing line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fourth:
When the child component's
data
option is a function, since the value ofparentVal(Vue.options.data)
isundefined
,childValue(data(){...})
is directly used as the value ofChild.options.data
, and still Is afunction
.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dividing line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fifth:
Even if the data function does not return a value, it will not be
getData(undefined, vm)
. Simple analysis of the source code will know.In short, the value of
vm.$options.data
is either afunction
orundefined
. Where do I miss it?@yyx990803 @hack2root
903be9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core tests are passing, but on CI this commit caused some Weex-related tests to fail.