A RetroSearch Logo

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

Search Query:

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

properly handle cosntructor options modification before global mixin … · vuejs/vue@4cf4982 · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+56

-8

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+56

-8

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

@@ -14,6 +14,7 @@ declare interface Component {

14 14

static extend: (options: Object) => Function;

15 15

static superOptions: Object;

16 16

static extendOptions: Object;

17 +

static sealedOptions: Object;

17 18

static super: Class<Component>;

18 19

// assets

19 20

static directive: (id: string, def?: Function | Object) => Function | Object | void;

Original file line number Diff line number Diff line change

@@ -1,7 +1,7 @@

1 1

/* @flow */

2 2 3 3

import config from '../config'

4 -

import { warn, mergeOptions } from '../util/index'

4 +

import { warn, extend, mergeOptions } from '../util/index'

5 5

import { defineComputed, proxy } from '../instance/state'

6 6 7 7

export function initExtend (Vue: GlobalAPI) {

@@ -78,6 +78,7 @@ export function initExtend (Vue: GlobalAPI) {

78 78

// been updated.

79 79

Sub.superOptions = Super.options

80 80

Sub.extendOptions = extendOptions

81 +

Sub.sealedOptions = extend({}, Sub.options)

81 82 82 83

// cache constructor

83 84

cachedCtors[SuperId] = Sub

Original file line number Diff line number Diff line change

@@ -8,7 +8,7 @@ import { initRender } from './render'

8 8

import { initEvents } from './events'

9 9

import { initInjections } from './inject'

10 10

import { initLifecycle, callHook } from './lifecycle'

11 -

import { mergeOptions, formatComponentName } from '../util/index'

11 +

import { extend, mergeOptions, formatComponentName } from '../util/index'

12 12 13 13

let uid = 0

14 14

@@ -88,18 +88,34 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {

88 88

if (Ctor.super) {

89 89

const superOptions = Ctor.super.options

90 90

const cachedSuperOptions = Ctor.superOptions

91 -

const extendOptions = Ctor.extendOptions

92 91

if (superOptions !== cachedSuperOptions) {

93 -

// super option changed

92 +

// super option changed,

93 +

// need to resolve new options.

94 94

Ctor.superOptions = superOptions

95 -

extendOptions.render = options.render

96 -

extendOptions.staticRenderFns = options.staticRenderFns

97 -

extendOptions._scopeId = options._scopeId

98 -

options = Ctor.options = mergeOptions(superOptions, extendOptions)

95 +

// check if there are any late-modified/attached options (#4976)

96 +

const modifiedOptions = resolveModifiedOptions(Ctor)

97 +

// update base extend options

98 +

if (modifiedOptions) {

99 +

extend(Ctor.extendOptions, modifiedOptions)

100 +

}

101 +

options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions)

99 102

if (options.name) {

100 103

options.components[options.name] = Ctor

101 104

}

102 105

}

103 106

}

104 107

return options

105 108

}

109 + 110 +

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

111 +

let res

112 +

const options = Ctor.options

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]

118 +

}

119 +

}

120 +

return res

121 +

}

Original file line number Diff line number Diff line change

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

84 84 85 85

expect(vm.$el.children[0].hasAttribute('foo')).toBe(true)

86 86

})

87 + 88 +

// #4976

89 +

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

90 +

const Test = Vue.extend({})

91 + 92 +

// Inject options later

93 +

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

94 +

Test.options.computed = {

95 +

$style: () => 123

96 +

}

97 + 98 +

const spy = jasmine.createSpy('mixin')

99 +

Test.options.beforeCreate = [spy]

100 + 101 +

// Update super constructor's options

102 +

Vue.mixin({})

103 + 104 +

// mount the component

105 +

const vm = new Test({

106 +

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

107 +

}).$mount()

108 + 109 +

expect(spy).toHaveBeenCalled()

110 +

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

111 +

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

112 + 113 +

// Should not be dropped

114 +

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

115 +

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

116 +

})

87 117

})

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