A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/7fa8fa76fe4a8450e0407cf64d704ac8df00c0c2 below:

avoid duplicate lifecycle hooks during constructor resolution · vuejs/vue@7fa8fa7 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+41

-14

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+41

-14

lines changed Original file line number Diff line number Diff line change

@@ -86,7 +86,7 @@ function initInternalComponent (vm: Component, options: InternalComponentOptions

86 86

export function resolveConstructorOptions (Ctor: Class<Component>) {

87 87

let options = Ctor.options

88 88

if (Ctor.super) {

89 -

const superOptions = Ctor.super.options

89 +

const superOptions = resolveConstructorOptions(Ctor.super)

90 90

const cachedSuperOptions = Ctor.superOptions

91 91

if (superOptions !== cachedSuperOptions) {

92 92

// super option changed,

@@ -108,14 +108,31 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {

108 108

}

109 109 110 110

function resolveModifiedOptions (Ctor: Class<Component>): ?Object {

111 -

let res

112 -

const options = Ctor.options

111 +

let modified

112 +

const latest = Ctor.options

113 113

const sealed = Ctor.sealedOptions

114 -

for (const key in options) {

115 -

if (sealed[key] !== options[key]) {

116 -

if (!res) res = {}

117 -

res[key] = options[key]

114 +

for (const key in latest) {

115 +

if (latest[key] !== sealed[key]) {

116 +

if (!modified) modified = {}

117 +

modified[key] = dedupe(latest[key], sealed[key])

118 118

}

119 119

}

120 -

return res

120 +

return modified

121 +

}

122 + 123 +

function dedupe (latest, sealed) {

124 +

// compare latest and sealed to ensure lifecycle hooks won't be duplicated

125 +

// between merges

126 +

if (Array.isArray(latest)) {

127 +

const res = []

128 +

sealed = Array.isArray(sealed) ? sealed : [sealed]

129 +

for (let i = 0; i < latest.length; i++) {

130 +

if (sealed.indexOf(latest[i]) < 0) {

131 +

res.push(latest[i])

132 +

}

133 +

}

134 +

return res

135 +

} else {

136 +

return latest

137 +

}

121 138

}

Original file line number Diff line number Diff line change

@@ -87,31 +87,41 @@ describe('Global API: mixin', () => {

87 87 88 88

// #4976

89 89

it('should not drop late-attached custom options on existing constructors', () => {

90 -

const Test = Vue.extend({})

90 +

const baseSpy = jasmine.createSpy('base')

91 +

const Base = Vue.extend({

92 +

beforeCreate: baseSpy

93 +

})

94 + 95 +

const Test = Base.extend({})

91 96 92 97

// Inject options later

93 98

// vue-loader and vue-hot-reload-api are doing like this

94 99

Test.options.computed = {

95 100

$style: () => 123

96 101

}

97 102 98 -

const spy = jasmine.createSpy('mixin')

99 -

Test.options.beforeCreate = [spy]

103 +

const spy = jasmine.createSpy('late attached')

104 +

Test.options.beforeCreate = Test.options.beforeCreate.concat(spy)

100 105 101 106

// Update super constructor's options

102 -

Vue.mixin({})

107 +

const mixinSpy = jasmine.createSpy('mixin')

108 +

Vue.mixin({

109 +

beforeCreate: mixinSpy

110 +

})

103 111 104 112

// mount the component

105 113

const vm = new Test({

106 114

template: '<div>{{ $style }}</div>'

107 115

}).$mount()

108 116 109 -

expect(spy).toHaveBeenCalled()

117 +

expect(spy.calls.count()).toBe(1)

118 +

expect(baseSpy.calls.count()).toBe(1)

119 +

expect(mixinSpy.calls.count()).toBe(1)

110 120

expect(vm.$el.textContent).toBe('123')

111 121

expect(vm.$style).toBe(123)

112 122 113 123

// Should not be dropped

114 124

expect(Test.options.computed.$style()).toBe(123)

115 -

expect(Test.options.beforeCreate).toEqual([spy])

125 +

expect(Test.options.beforeCreate).toEqual([mixinSpy, baseSpy, spy])

116 126

})

117 127

})

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4