A RetroSearch Logo

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

Search Query:

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

dedupe lifecycle hooks during options merge · vuejs/vue@edf7df0 · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+64

-40

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+64

-40

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

@@ -117,32 +117,12 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {

117 117

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

118 118

let modified

119 119

const latest = Ctor.options

120 -

const extended = Ctor.extendOptions

121 120

const sealed = Ctor.sealedOptions

122 121

for (const key in latest) {

123 122

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

124 123

if (!modified) modified = {}

125 -

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

124 +

modified[key] = latest[key]

126 125

}

127 126

}

128 127

return modified

129 128

}

130 - 131 -

function dedupe (latest, extended, sealed) {

132 -

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

133 -

// between merges

134 -

if (Array.isArray(latest)) {

135 -

const res = []

136 -

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

137 -

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

138 -

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

139 -

// push original options and not sealed options to exclude duplicated options

140 -

if (extended.indexOf(latest[i]) >= 0 || sealed.indexOf(latest[i]) < 0) {

141 -

res.push(latest[i])

142 -

}

143 -

}

144 -

return res

145 -

} else {

146 -

return latest

147 -

}

148 -

}

Original file line number Diff line number Diff line change

@@ -147,13 +147,26 @@ function mergeHook (

147 147

parentVal: ?Array<Function>,

148 148

childVal: ?Function | ?Array<Function>

149 149

): ?Array<Function> {

150 -

return childVal

150 +

const res = childVal

151 151

? parentVal

152 152

? parentVal.concat(childVal)

153 153

: Array.isArray(childVal)

154 154

? childVal

155 155

: [childVal]

156 156

: parentVal

157 +

return res

158 +

? dedupeHooks(res)

159 +

: res

160 +

}

161 + 162 +

function dedupeHooks (hooks) {

163 +

const res = []

164 +

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

165 +

if (res.indexOf(hooks[i]) === -1) {

166 +

res.push(hooks[i])

167 +

}

168 +

}

169 +

return res

157 170

}

158 171 159 172

LIFECYCLE_HOOKS.forEach(hook => {

@@ -382,7 +395,7 @@ export function mergeOptions (

382 395

}

383 396 384 397

if (typeof child === 'function') {

385 -

child = child.extendOptions

398 +

child = child.options

386 399

}

387 400 388 401

normalizeProps(child, vm)

Original file line number Diff line number Diff line change

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

167 167

it('chain call', () => {

168 168

expect(Vue.mixin({})).toBe(Vue)

169 169

})

170 + 171 +

// #9198

172 +

it('should not mix global mixin lifecycle hook twice', () => {

173 +

const spy = jasmine.createSpy('global mixed in lifecycle hook')

174 +

Vue.mixin({

175 +

created: spy

176 +

})

177 + 178 +

const mixin1 = Vue.extend({

179 +

methods: {

180 +

a() {}

181 +

}

182 +

})

183 + 184 +

const mixin2 = Vue.extend({

185 +

mixins: [mixin1]

186 +

})

187 + 188 +

const Child = Vue.extend({

189 +

mixins: [mixin2],

190 +

})

191 + 192 +

const vm = new Child()

193 + 194 +

expect(typeof vm.$options.methods.a).toBe('function')

195 +

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

196 +

})

170 197

})

Original file line number Diff line number Diff line change

@@ -110,31 +110,35 @@ describe('Options mixins', () => {

110 110

expect(vm.$options.directives.c).toBeDefined()

111 111

})

112 112 113 -

it('should not mix global mixined lifecycle hook twice', () => {

114 -

const spy = jasmine.createSpy('global mixed in lifecycle hook')

115 -

Vue.mixin({

116 -

created() {

117 -

spy()

118 -

}

119 -

})

113 +

it('should accept further extended constructors as mixins', () => {

114 +

const spy1 = jasmine.createSpy('mixinA')

115 +

const spy2 = jasmine.createSpy('mixinB')

120 116 121 -

const mixin1 = Vue.extend({

117 +

const mixinA = Vue.extend({

118 +

created: spy1,

119 +

directives: {

120 +

c: {}

121 +

},

122 122

methods: {

123 -

a() {}

123 +

a: function () {}

124 124

}

125 125

})

126 126 127 -

const mixin2 = Vue.extend({

128 -

mixins: [mixin1],

127 +

const mixinB = mixinA.extend({

128 +

created: spy2

129 129

})

130 130 131 -

const Child = Vue.extend({

132 -

mixins: [mixin2],

131 +

const vm = new Vue({

132 +

mixins: [mixinB],

133 +

methods: {

134 +

b: function () {}

135 +

}

133 136

})

134 137 135 -

const vm = new Child()

136 - 137 -

expect(typeof vm.$options.methods.a).toBe('function')

138 -

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

138 +

expect(spy1).toHaveBeenCalledTimes(1)

139 +

expect(spy2).toHaveBeenCalledTimes(1)

140 +

expect(vm.a).toBeDefined()

141 +

expect(vm.b).toBeDefined()

142 +

expect(vm.$options.directives.c).toBeDefined()

139 143

})

140 144

})

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