Skip to content

Commit 25c8476

Browse files
blake-newmanyyx990803
authored andcommitted
[Fix] [ISSUE-2687] Fix data functions being called twice. (vuejs#2689)
- 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
1 parent 6bd7a9c commit 25c8476

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/instance/internal/init.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ export default function (Vue) {
9494
// it will be filled up in _initScope().
9595
this._data = {}
9696

97-
// save raw constructor data before merge
98-
// so that we know which properties are provided at
99-
// instantiation.
100-
this._runtimeData = options.data
101-
10297
// call init hook
10398
this._callHook('init')
10499

src/instance/internal/state.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ export default function (Vue) {
8787
)
8888
}
8989
var props = this._props
90-
var runtimeData = this._runtimeData
91-
? typeof this._runtimeData === 'function'
92-
? this._runtimeData()
93-
: this._runtimeData
94-
: null
9590
// proxy data on instance
9691
var keys = Object.keys(data)
9792
var i, key
@@ -104,7 +99,7 @@ export default function (Vue) {
10499
// template prop present
105100
if (
106101
!props || !hasOwn(props, key) ||
107-
(runtimeData && hasOwn(runtimeData, key) && props[key].raw === null)
102+
(data && hasOwn(data, key) && props[key].raw === null)
108103
) {
109104
this._proxy(key)
110105
} else if (process.env.NODE_ENV !== 'production') {

test/unit/specs/instance/state_spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ describe('Instance state initialization', function () {
99
expect('should return an object').toHaveBeenWarned()
1010
})
1111

12+
it('should initialize data once per strat', function () {
13+
var spyOncePerStrat = jasmine.createSpy('called once per strat')
14+
const VM = Vue.extend({
15+
data: function () {
16+
spyOncePerStrat()
17+
return {
18+
result: 'false'
19+
}
20+
}
21+
})
22+
new VM({
23+
data: function () {
24+
spyOncePerStrat()
25+
return {
26+
result: 'true'
27+
}
28+
}
29+
})
30+
expect(spyOncePerStrat.calls.count()).toBe(2)
31+
})
32+
1233
describe('data proxy', function () {
1334
var data = {
1435
a: 0,

0 commit comments

Comments
 (0)
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