vue 2.6.2 → 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vue.js v2.6.2
2
+ * Vue.js v2.6.6
3
3
  * (c) 2014-2019 Evan You
4
4
  * Released under the MIT License.
5
5
  */
@@ -529,6 +529,7 @@
529
529
  var isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios');
530
530
  var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
531
531
  var isPhantomJS = UA && /phantomjs/.test(UA);
532
+ var isFF = UA && UA.match(/firefox\/(\d+)/);
532
533
 
533
534
  // Firefox has a "watch" function on Object.prototype...
534
535
  var nativeWatch = ({}).watch;
@@ -1858,7 +1859,11 @@
1858
1859
  try {
1859
1860
  return config.errorHandler.call(null, err, vm, info)
1860
1861
  } catch (e) {
1861
- logError(e, null, 'config.errorHandler');
1862
+ // if the user intentionally throws the original error in the handler,
1863
+ // do not log it twice
1864
+ if (e !== err) {
1865
+ logError(e, null, 'config.errorHandler');
1866
+ }
1862
1867
  }
1863
1868
  }
1864
1869
  logError(err, vm, info);
@@ -2399,2437 +2404,2483 @@
2399
2404
 
2400
2405
  /* */
2401
2406
 
2402
- function ensureCtor (comp, base) {
2403
- if (
2404
- comp.__esModule ||
2405
- (hasSymbol && comp[Symbol.toStringTag] === 'Module')
2406
- ) {
2407
- comp = comp.default;
2407
+ function initProvide (vm) {
2408
+ var provide = vm.$options.provide;
2409
+ if (provide) {
2410
+ vm._provided = typeof provide === 'function'
2411
+ ? provide.call(vm)
2412
+ : provide;
2408
2413
  }
2409
- return isObject(comp)
2410
- ? base.extend(comp)
2411
- : comp
2412
2414
  }
2413
2415
 
2414
- function createAsyncPlaceholder (
2415
- factory,
2416
- data,
2417
- context,
2418
- children,
2419
- tag
2420
- ) {
2421
- var node = createEmptyVNode();
2422
- node.asyncFactory = factory;
2423
- node.asyncMeta = { data: data, context: context, children: children, tag: tag };
2424
- return node
2425
- }
2426
-
2427
- function resolveAsyncComponent (
2428
- factory,
2429
- baseCtor,
2430
- context
2431
- ) {
2432
- if (isTrue(factory.error) && isDef(factory.errorComp)) {
2433
- return factory.errorComp
2434
- }
2435
-
2436
- if (isDef(factory.resolved)) {
2437
- return factory.resolved
2438
- }
2439
-
2440
- if (isTrue(factory.loading) && isDef(factory.loadingComp)) {
2441
- return factory.loadingComp
2442
- }
2443
-
2444
- if (isDef(factory.contexts)) {
2445
- // already pending
2446
- factory.contexts.push(context);
2447
- } else {
2448
- var contexts = factory.contexts = [context];
2449
- var sync = true;
2450
-
2451
- var forceRender = function (renderCompleted) {
2452
- for (var i = 0, l = contexts.length; i < l; i++) {
2453
- contexts[i].$forceUpdate();
2454
- }
2455
-
2456
- if (renderCompleted) {
2457
- contexts.length = 0;
2458
- }
2459
- };
2460
-
2461
- var resolve = once(function (res) {
2462
- // cache resolved
2463
- factory.resolved = ensureCtor(res, baseCtor);
2464
- // invoke callbacks only if this is not a synchronous resolve
2465
- // (async resolves are shimmed as synchronous during SSR)
2466
- if (!sync) {
2467
- forceRender(true);
2468
- } else {
2469
- contexts.length = 0;
2470
- }
2471
- });
2472
-
2473
- var reject = once(function (reason) {
2474
- warn(
2475
- "Failed to resolve async component: " + (String(factory)) +
2476
- (reason ? ("\nReason: " + reason) : '')
2477
- );
2478
- if (isDef(factory.errorComp)) {
2479
- factory.error = true;
2480
- forceRender(true);
2416
+ function initInjections (vm) {
2417
+ var result = resolveInject(vm.$options.inject, vm);
2418
+ if (result) {
2419
+ toggleObserving(false);
2420
+ Object.keys(result).forEach(function (key) {
2421
+ /* istanbul ignore else */
2422
+ {
2423
+ defineReactive$$1(vm, key, result[key], function () {
2424
+ warn(
2425
+ "Avoid mutating an injected value directly since the changes will be " +
2426
+ "overwritten whenever the provided component re-renders. " +
2427
+ "injection being mutated: \"" + key + "\"",
2428
+ vm
2429
+ );
2430
+ });
2481
2431
  }
2482
2432
  });
2433
+ toggleObserving(true);
2434
+ }
2435
+ }
2483
2436
 
2484
- var res = factory(resolve, reject);
2485
-
2486
- if (isObject(res)) {
2487
- if (isPromise(res)) {
2488
- // () => Promise
2489
- if (isUndef(factory.resolved)) {
2490
- res.then(resolve, reject);
2491
- }
2492
- } else if (isPromise(res.component)) {
2493
- res.component.then(resolve, reject);
2494
-
2495
- if (isDef(res.error)) {
2496
- factory.errorComp = ensureCtor(res.error, baseCtor);
2497
- }
2437
+ function resolveInject (inject, vm) {
2438
+ if (inject) {
2439
+ // inject is :any because flow is not smart enough to figure out cached
2440
+ var result = Object.create(null);
2441
+ var keys = hasSymbol
2442
+ ? Reflect.ownKeys(inject)
2443
+ : Object.keys(inject);
2498
2444
 
2499
- if (isDef(res.loading)) {
2500
- factory.loadingComp = ensureCtor(res.loading, baseCtor);
2501
- if (res.delay === 0) {
2502
- factory.loading = true;
2503
- } else {
2504
- setTimeout(function () {
2505
- if (isUndef(factory.resolved) && isUndef(factory.error)) {
2506
- factory.loading = true;
2507
- forceRender(false);
2508
- }
2509
- }, res.delay || 200);
2510
- }
2445
+ for (var i = 0; i < keys.length; i++) {
2446
+ var key = keys[i];
2447
+ // #6574 in case the inject object is observed...
2448
+ if (key === '__ob__') { continue }
2449
+ var provideKey = inject[key].from;
2450
+ var source = vm;
2451
+ while (source) {
2452
+ if (source._provided && hasOwn(source._provided, provideKey)) {
2453
+ result[key] = source._provided[provideKey];
2454
+ break
2511
2455
  }
2512
-
2513
- if (isDef(res.timeout)) {
2514
- setTimeout(function () {
2515
- if (isUndef(factory.resolved)) {
2516
- reject(
2517
- "timeout (" + (res.timeout) + "ms)"
2518
- );
2519
- }
2520
- }, res.timeout);
2456
+ source = source.$parent;
2457
+ }
2458
+ if (!source) {
2459
+ if ('default' in inject[key]) {
2460
+ var provideDefault = inject[key].default;
2461
+ result[key] = typeof provideDefault === 'function'
2462
+ ? provideDefault.call(vm)
2463
+ : provideDefault;
2464
+ } else {
2465
+ warn(("Injection \"" + key + "\" not found"), vm);
2521
2466
  }
2522
2467
  }
2523
2468
  }
2524
-
2525
- sync = false;
2526
- // return in case resolved synchronously
2527
- return factory.loading
2528
- ? factory.loadingComp
2529
- : factory.resolved
2469
+ return result
2530
2470
  }
2531
2471
  }
2532
2472
 
2533
2473
  /* */
2534
2474
 
2535
- function isAsyncPlaceholder (node) {
2536
- return node.isComment && node.asyncFactory
2537
- }
2538
2475
 
2539
- /* */
2540
2476
 
2541
- function getFirstComponentChild (children) {
2542
- if (Array.isArray(children)) {
2543
- for (var i = 0; i < children.length; i++) {
2544
- var c = children[i];
2545
- if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) {
2546
- return c
2477
+ /**
2478
+ * Runtime helper for resolving raw children VNodes into a slot object.
2479
+ */
2480
+ function resolveSlots (
2481
+ children,
2482
+ context
2483
+ ) {
2484
+ if (!children || !children.length) {
2485
+ return {}
2486
+ }
2487
+ var slots = {};
2488
+ for (var i = 0, l = children.length; i < l; i++) {
2489
+ var child = children[i];
2490
+ var data = child.data;
2491
+ // remove slot attribute if the node is resolved as a Vue slot node
2492
+ if (data && data.attrs && data.attrs.slot) {
2493
+ delete data.attrs.slot;
2494
+ }
2495
+ // named slots should only be respected if the vnode was rendered in the
2496
+ // same context.
2497
+ if ((child.context === context || child.fnContext === context) &&
2498
+ data && data.slot != null
2499
+ ) {
2500
+ var name = data.slot;
2501
+ var slot = (slots[name] || (slots[name] = []));
2502
+ if (child.tag === 'template') {
2503
+ slot.push.apply(slot, child.children || []);
2504
+ } else {
2505
+ slot.push(child);
2547
2506
  }
2507
+ } else {
2508
+ (slots.default || (slots.default = [])).push(child);
2509
+ }
2510
+ }
2511
+ // ignore slots that contains only whitespace
2512
+ for (var name$1 in slots) {
2513
+ if (slots[name$1].every(isWhitespace)) {
2514
+ delete slots[name$1];
2548
2515
  }
2549
2516
  }
2517
+ return slots
2550
2518
  }
2551
2519
 
2552
- /* */
2520
+ function isWhitespace (node) {
2521
+ return (node.isComment && !node.asyncFactory) || node.text === ' '
2522
+ }
2553
2523
 
2554
2524
  /* */
2555
2525
 
2556
- function initEvents (vm) {
2557
- vm._events = Object.create(null);
2558
- vm._hasHookEvent = false;
2559
- // init parent attached events
2560
- var listeners = vm.$options._parentListeners;
2561
- if (listeners) {
2562
- updateComponentListeners(vm, listeners);
2526
+ function normalizeScopedSlots (
2527
+ slots,
2528
+ normalSlots,
2529
+ prevSlots
2530
+ ) {
2531
+ var res;
2532
+ if (!slots) {
2533
+ res = {};
2534
+ } else if (slots._normalized) {
2535
+ // fast path 1: child component re-render only, parent did not change
2536
+ return slots._normalized
2537
+ } else if (
2538
+ slots.$stable &&
2539
+ prevSlots &&
2540
+ prevSlots !== emptyObject &&
2541
+ Object.keys(normalSlots).length === 0
2542
+ ) {
2543
+ // fast path 2: stable scoped slots w/ no normal slots to proxy,
2544
+ // only need to normalize once
2545
+ return prevSlots
2546
+ } else {
2547
+ res = {};
2548
+ for (var key in slots) {
2549
+ if (slots[key] && key[0] !== '$') {
2550
+ res[key] = normalizeScopedSlot(normalSlots, key, slots[key]);
2551
+ }
2552
+ }
2553
+ }
2554
+ // expose normal slots on scopedSlots
2555
+ for (var key$1 in normalSlots) {
2556
+ if (!(key$1 in res)) {
2557
+ res[key$1] = proxyNormalSlot(normalSlots, key$1);
2558
+ }
2559
+ }
2560
+ // avoriaz seems to mock a non-extensible $scopedSlots object
2561
+ // and when that is passed down this would cause an error
2562
+ if (slots && Object.isExtensible(slots)) {
2563
+ (slots)._normalized = res;
2563
2564
  }
2565
+ def(res, '$stable', slots ? !!slots.$stable : true);
2566
+ return res
2564
2567
  }
2565
2568
 
2566
- var target;
2567
-
2568
- function add (event, fn) {
2569
- target.$on(event, fn);
2569
+ function normalizeScopedSlot(normalSlots, key, fn) {
2570
+ var normalized = function () {
2571
+ var res = arguments.length ? fn.apply(null, arguments) : fn({});
2572
+ res = res && typeof res === 'object' && !Array.isArray(res)
2573
+ ? [res] // single vnode
2574
+ : normalizeChildren(res);
2575
+ return res && res.length === 0
2576
+ ? undefined
2577
+ : res
2578
+ };
2579
+ // this is a slot using the new v-slot syntax without scope. although it is
2580
+ // compiled as a scoped slot, render fn users would expect it to be present
2581
+ // on this.$slots because the usage is semantically a normal slot.
2582
+ if (fn.proxy) {
2583
+ Object.defineProperty(normalSlots, key, {
2584
+ get: normalized,
2585
+ enumerable: true,
2586
+ configurable: true
2587
+ });
2588
+ }
2589
+ return normalized
2570
2590
  }
2571
2591
 
2572
- function remove$1 (event, fn) {
2573
- target.$off(event, fn);
2592
+ function proxyNormalSlot(slots, key) {
2593
+ return function () { return slots[key]; }
2574
2594
  }
2575
2595
 
2576
- function createOnceHandler (event, fn) {
2577
- var _target = target;
2578
- return function onceHandler () {
2579
- var res = fn.apply(null, arguments);
2580
- if (res !== null) {
2581
- _target.$off(event, onceHandler);
2582
- }
2583
- }
2584
- }
2596
+ /* */
2585
2597
 
2586
- function updateComponentListeners (
2587
- vm,
2588
- listeners,
2589
- oldListeners
2598
+ /**
2599
+ * Runtime helper for rendering v-for lists.
2600
+ */
2601
+ function renderList (
2602
+ val,
2603
+ render
2590
2604
  ) {
2591
- target = vm;
2592
- updateListeners(listeners, oldListeners || {}, add, remove$1, createOnceHandler, vm);
2593
- target = undefined;
2594
- }
2595
-
2596
- function eventsMixin (Vue) {
2597
- var hookRE = /^hook:/;
2598
- Vue.prototype.$on = function (event, fn) {
2599
- var vm = this;
2600
- if (Array.isArray(event)) {
2601
- for (var i = 0, l = event.length; i < l; i++) {
2602
- vm.$on(event[i], fn);
2603
- }
2604
- } else {
2605
- (vm._events[event] || (vm._events[event] = [])).push(fn);
2606
- // optimize hook:event cost by using a boolean flag marked at registration
2607
- // instead of a hash lookup
2608
- if (hookRE.test(event)) {
2609
- vm._hasHookEvent = true;
2610
- }
2611
- }
2612
- return vm
2613
- };
2614
-
2615
- Vue.prototype.$once = function (event, fn) {
2616
- var vm = this;
2617
- function on () {
2618
- vm.$off(event, on);
2619
- fn.apply(vm, arguments);
2620
- }
2621
- on.fn = fn;
2622
- vm.$on(event, on);
2623
- return vm
2624
- };
2625
-
2626
- Vue.prototype.$off = function (event, fn) {
2627
- var vm = this;
2628
- // all
2629
- if (!arguments.length) {
2630
- vm._events = Object.create(null);
2631
- return vm
2632
- }
2633
- // array of events
2634
- if (Array.isArray(event)) {
2635
- for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {
2636
- vm.$off(event[i$1], fn);
2637
- }
2638
- return vm
2639
- }
2640
- // specific event
2641
- var cbs = vm._events[event];
2642
- if (!cbs) {
2643
- return vm
2644
- }
2645
- if (!fn) {
2646
- vm._events[event] = null;
2647
- return vm
2605
+ var ret, i, l, keys, key;
2606
+ if (Array.isArray(val) || typeof val === 'string') {
2607
+ ret = new Array(val.length);
2608
+ for (i = 0, l = val.length; i < l; i++) {
2609
+ ret[i] = render(val[i], i);
2648
2610
  }
2649
- // specific handler
2650
- var cb;
2651
- var i = cbs.length;
2652
- while (i--) {
2653
- cb = cbs[i];
2654
- if (cb === fn || cb.fn === fn) {
2655
- cbs.splice(i, 1);
2656
- break
2657
- }
2611
+ } else if (typeof val === 'number') {
2612
+ ret = new Array(val);
2613
+ for (i = 0; i < val; i++) {
2614
+ ret[i] = render(i + 1, i);
2658
2615
  }
2659
- return vm
2660
- };
2661
-
2662
- Vue.prototype.$emit = function (event) {
2663
- var vm = this;
2664
- {
2665
- var lowerCaseEvent = event.toLowerCase();
2666
- if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
2667
- tip(
2668
- "Event \"" + lowerCaseEvent + "\" is emitted in component " +
2669
- (formatComponentName(vm)) + " but the handler is registered for \"" + event + "\". " +
2670
- "Note that HTML attributes are case-insensitive and you cannot use " +
2671
- "v-on to listen to camelCase events when using in-DOM templates. " +
2672
- "You should probably use \"" + (hyphenate(event)) + "\" instead of \"" + event + "\"."
2673
- );
2616
+ } else if (isObject(val)) {
2617
+ if (hasSymbol && val[Symbol.iterator]) {
2618
+ ret = [];
2619
+ var iterator = val[Symbol.iterator]();
2620
+ var result = iterator.next();
2621
+ while (!result.done) {
2622
+ ret.push(render(result.value, ret.length));
2623
+ result = iterator.next();
2674
2624
  }
2675
- }
2676
- var cbs = vm._events[event];
2677
- if (cbs) {
2678
- cbs = cbs.length > 1 ? toArray(cbs) : cbs;
2679
- var args = toArray(arguments, 1);
2680
- var info = "event handler for \"" + event + "\"";
2681
- for (var i = 0, l = cbs.length; i < l; i++) {
2682
- invokeWithErrorHandling(cbs[i], vm, args, vm, info);
2625
+ } else {
2626
+ keys = Object.keys(val);
2627
+ ret = new Array(keys.length);
2628
+ for (i = 0, l = keys.length; i < l; i++) {
2629
+ key = keys[i];
2630
+ ret[i] = render(val[key], key, i);
2683
2631
  }
2684
2632
  }
2685
- return vm
2686
- };
2633
+ }
2634
+ if (!isDef(ret)) {
2635
+ ret = [];
2636
+ }
2637
+ (ret)._isVList = true;
2638
+ return ret
2687
2639
  }
2688
2640
 
2689
2641
  /* */
2690
2642
 
2691
-
2692
-
2693
2643
  /**
2694
- * Runtime helper for resolving raw children VNodes into a slot object.
2644
+ * Runtime helper for rendering <slot>
2695
2645
  */
2696
- function resolveSlots (
2697
- children,
2698
- context
2646
+ function renderSlot (
2647
+ name,
2648
+ fallback,
2649
+ props,
2650
+ bindObject
2699
2651
  ) {
2700
- if (!children || !children.length) {
2701
- return {}
2702
- }
2703
- var slots = {};
2704
- for (var i = 0, l = children.length; i < l; i++) {
2705
- var child = children[i];
2706
- var data = child.data;
2707
- // remove slot attribute if the node is resolved as a Vue slot node
2708
- if (data && data.attrs && data.attrs.slot) {
2709
- delete data.attrs.slot;
2710
- }
2711
- // named slots should only be respected if the vnode was rendered in the
2712
- // same context.
2713
- if ((child.context === context || child.fnContext === context) &&
2714
- data && data.slot != null
2715
- ) {
2716
- var name = data.slot;
2717
- var slot = (slots[name] || (slots[name] = []));
2718
- if (child.tag === 'template') {
2719
- slot.push.apply(slot, child.children || []);
2720
- } else {
2721
- slot.push(child);
2652
+ var scopedSlotFn = this.$scopedSlots[name];
2653
+ var nodes;
2654
+ if (scopedSlotFn) { // scoped slot
2655
+ props = props || {};
2656
+ if (bindObject) {
2657
+ if (!isObject(bindObject)) {
2658
+ warn(
2659
+ 'slot v-bind without argument expects an Object',
2660
+ this
2661
+ );
2722
2662
  }
2723
- } else {
2724
- (slots.default || (slots.default = [])).push(child);
2725
- }
2726
- }
2727
- // ignore slots that contains only whitespace
2728
- for (var name$1 in slots) {
2729
- if (slots[name$1].every(isWhitespace)) {
2730
- delete slots[name$1];
2663
+ props = extend(extend({}, bindObject), props);
2731
2664
  }
2665
+ nodes = scopedSlotFn(props) || fallback;
2666
+ } else {
2667
+ nodes = this.$slots[name] || fallback;
2732
2668
  }
2733
- return slots
2734
- }
2735
-
2736
- function isWhitespace (node) {
2737
- return (node.isComment && !node.asyncFactory) || node.text === ' '
2738
- }
2739
2669
 
2740
- function resolveScopedSlots (
2741
- fns, // see flow/vnode
2742
- hasDynamicKeys,
2743
- res
2744
- ) {
2745
- res = res || { $stable: !hasDynamicKeys };
2746
- for (var i = 0; i < fns.length; i++) {
2747
- var slot = fns[i];
2748
- if (Array.isArray(slot)) {
2749
- resolveScopedSlots(slot, hasDynamicKeys, res);
2750
- } else if (slot) {
2751
- res[slot.key] = slot.fn;
2752
- }
2670
+ var target = props && props.slot;
2671
+ if (target) {
2672
+ return this.$createElement('template', { slot: target }, nodes)
2673
+ } else {
2674
+ return nodes
2753
2675
  }
2754
- return res
2755
2676
  }
2756
2677
 
2757
2678
  /* */
2758
2679
 
2759
- var activeInstance = null;
2760
- var isUpdatingChildComponent = false;
2761
-
2762
- function setActiveInstance(vm) {
2763
- var prevActiveInstance = activeInstance;
2764
- activeInstance = vm;
2765
- return function () {
2766
- activeInstance = prevActiveInstance;
2767
- }
2680
+ /**
2681
+ * Runtime helper for resolving filters
2682
+ */
2683
+ function resolveFilter (id) {
2684
+ return resolveAsset(this.$options, 'filters', id, true) || identity
2768
2685
  }
2769
2686
 
2770
- function initLifecycle (vm) {
2771
- var options = vm.$options;
2687
+ /* */
2772
2688
 
2773
- // locate first non-abstract parent
2774
- var parent = options.parent;
2775
- if (parent && !options.abstract) {
2776
- while (parent.$options.abstract && parent.$parent) {
2777
- parent = parent.$parent;
2778
- }
2779
- parent.$children.push(vm);
2689
+ function isKeyNotMatch (expect, actual) {
2690
+ if (Array.isArray(expect)) {
2691
+ return expect.indexOf(actual) === -1
2692
+ } else {
2693
+ return expect !== actual
2780
2694
  }
2695
+ }
2781
2696
 
2782
- vm.$parent = parent;
2783
- vm.$root = parent ? parent.$root : vm;
2784
-
2785
- vm.$children = [];
2786
- vm.$refs = {};
2787
-
2788
- vm._watcher = null;
2789
- vm._inactive = null;
2790
- vm._directInactive = false;
2791
- vm._isMounted = false;
2792
- vm._isDestroyed = false;
2793
- vm._isBeingDestroyed = false;
2697
+ /**
2698
+ * Runtime helper for checking keyCodes from config.
2699
+ * exposed as Vue.prototype._k
2700
+ * passing in eventKeyName as last argument separately for backwards compat
2701
+ */
2702
+ function checkKeyCodes (
2703
+ eventKeyCode,
2704
+ key,
2705
+ builtInKeyCode,
2706
+ eventKeyName,
2707
+ builtInKeyName
2708
+ ) {
2709
+ var mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
2710
+ if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
2711
+ return isKeyNotMatch(builtInKeyName, eventKeyName)
2712
+ } else if (mappedKeyCode) {
2713
+ return isKeyNotMatch(mappedKeyCode, eventKeyCode)
2714
+ } else if (eventKeyName) {
2715
+ return hyphenate(eventKeyName) !== key
2716
+ }
2794
2717
  }
2795
2718
 
2796
- function lifecycleMixin (Vue) {
2797
- Vue.prototype._update = function (vnode, hydrating) {
2798
- var vm = this;
2799
- var prevEl = vm.$el;
2800
- var prevVnode = vm._vnode;
2801
- var restoreActiveInstance = setActiveInstance(vm);
2802
- vm._vnode = vnode;
2803
- // Vue.prototype.__patch__ is injected in entry points
2804
- // based on the rendering backend used.
2805
- if (!prevVnode) {
2806
- // initial render
2807
- vm.$el = vm.__patch__(vm.$el, vnode, hydrating, false /* removeOnly */);
2719
+ /* */
2720
+
2721
+ /**
2722
+ * Runtime helper for merging v-bind="object" into a VNode's data.
2723
+ */
2724
+ function bindObjectProps (
2725
+ data,
2726
+ tag,
2727
+ value,
2728
+ asProp,
2729
+ isSync
2730
+ ) {
2731
+ if (value) {
2732
+ if (!isObject(value)) {
2733
+ warn(
2734
+ 'v-bind without argument expects an Object or Array value',
2735
+ this
2736
+ );
2808
2737
  } else {
2809
- // updates
2810
- vm.$el = vm.__patch__(prevVnode, vnode);
2811
- }
2812
- restoreActiveInstance();
2813
- // update __vue__ reference
2814
- if (prevEl) {
2815
- prevEl.__vue__ = null;
2816
- }
2817
- if (vm.$el) {
2818
- vm.$el.__vue__ = vm;
2819
- }
2820
- // if parent is an HOC, update its $el as well
2821
- if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
2822
- vm.$parent.$el = vm.$el;
2823
- }
2824
- // updated hook is called by the scheduler to ensure that children are
2825
- // updated in a parent's updated hook.
2826
- };
2738
+ if (Array.isArray(value)) {
2739
+ value = toObject(value);
2740
+ }
2741
+ var hash;
2742
+ var loop = function ( key ) {
2743
+ if (
2744
+ key === 'class' ||
2745
+ key === 'style' ||
2746
+ isReservedAttribute(key)
2747
+ ) {
2748
+ hash = data;
2749
+ } else {
2750
+ var type = data.attrs && data.attrs.type;
2751
+ hash = asProp || config.mustUseProp(tag, type, key)
2752
+ ? data.domProps || (data.domProps = {})
2753
+ : data.attrs || (data.attrs = {});
2754
+ }
2755
+ var camelizedKey = camelize(key);
2756
+ if (!(key in hash) && !(camelizedKey in hash)) {
2757
+ hash[key] = value[key];
2827
2758
 
2828
- Vue.prototype.$forceUpdate = function () {
2829
- var vm = this;
2830
- if (vm._watcher) {
2831
- vm._watcher.update();
2832
- }
2833
- };
2759
+ if (isSync) {
2760
+ var on = data.on || (data.on = {});
2761
+ on[("update:" + camelizedKey)] = function ($event) {
2762
+ value[key] = $event;
2763
+ };
2764
+ }
2765
+ }
2766
+ };
2834
2767
 
2835
- Vue.prototype.$destroy = function () {
2836
- var vm = this;
2837
- if (vm._isBeingDestroyed) {
2838
- return
2839
- }
2840
- callHook(vm, 'beforeDestroy');
2841
- vm._isBeingDestroyed = true;
2842
- // remove self from parent
2843
- var parent = vm.$parent;
2844
- if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
2845
- remove(parent.$children, vm);
2846
- }
2847
- // teardown watchers
2848
- if (vm._watcher) {
2849
- vm._watcher.teardown();
2850
- }
2851
- var i = vm._watchers.length;
2852
- while (i--) {
2853
- vm._watchers[i].teardown();
2854
- }
2855
- // remove reference from data ob
2856
- // frozen object may not have observer.
2857
- if (vm._data.__ob__) {
2858
- vm._data.__ob__.vmCount--;
2859
- }
2860
- // call the last hook...
2861
- vm._isDestroyed = true;
2862
- // invoke destroy hooks on current rendered tree
2863
- vm.__patch__(vm._vnode, null);
2864
- // fire destroyed hook
2865
- callHook(vm, 'destroyed');
2866
- // turn off all instance listeners.
2867
- vm.$off();
2868
- // remove __vue__ reference
2869
- if (vm.$el) {
2870
- vm.$el.__vue__ = null;
2871
- }
2872
- // release circular reference (#6759)
2873
- if (vm.$vnode) {
2874
- vm.$vnode.parent = null;
2768
+ for (var key in value) loop( key );
2875
2769
  }
2876
- };
2770
+ }
2771
+ return data
2877
2772
  }
2878
2773
 
2879
- function mountComponent (
2880
- vm,
2881
- el,
2882
- hydrating
2774
+ /* */
2775
+
2776
+ /**
2777
+ * Runtime helper for rendering static trees.
2778
+ */
2779
+ function renderStatic (
2780
+ index,
2781
+ isInFor
2883
2782
  ) {
2884
- vm.$el = el;
2885
- if (!vm.$options.render) {
2886
- vm.$options.render = createEmptyVNode;
2887
- {
2888
- /* istanbul ignore if */
2889
- if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') ||
2890
- vm.$options.el || el) {
2891
- warn(
2892
- 'You are using the runtime-only build of Vue where the template ' +
2893
- 'compiler is not available. Either pre-compile the templates into ' +
2894
- 'render functions, or use the compiler-included build.',
2895
- vm
2896
- );
2897
- } else {
2898
- warn(
2899
- 'Failed to mount component: template or render function not defined.',
2900
- vm
2901
- );
2783
+ var cached = this._staticTrees || (this._staticTrees = []);
2784
+ var tree = cached[index];
2785
+ // if has already-rendered static tree and not inside v-for,
2786
+ // we can reuse the same tree.
2787
+ if (tree && !isInFor) {
2788
+ return tree
2789
+ }
2790
+ // otherwise, render a fresh tree.
2791
+ tree = cached[index] = this.$options.staticRenderFns[index].call(
2792
+ this._renderProxy,
2793
+ null,
2794
+ this // for render fns generated for functional component templates
2795
+ );
2796
+ markStatic(tree, ("__static__" + index), false);
2797
+ return tree
2798
+ }
2799
+
2800
+ /**
2801
+ * Runtime helper for v-once.
2802
+ * Effectively it means marking the node as static with a unique key.
2803
+ */
2804
+ function markOnce (
2805
+ tree,
2806
+ index,
2807
+ key
2808
+ ) {
2809
+ markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true);
2810
+ return tree
2811
+ }
2812
+
2813
+ function markStatic (
2814
+ tree,
2815
+ key,
2816
+ isOnce
2817
+ ) {
2818
+ if (Array.isArray(tree)) {
2819
+ for (var i = 0; i < tree.length; i++) {
2820
+ if (tree[i] && typeof tree[i] !== 'string') {
2821
+ markStaticNode(tree[i], (key + "_" + i), isOnce);
2902
2822
  }
2903
2823
  }
2824
+ } else {
2825
+ markStaticNode(tree, key, isOnce);
2904
2826
  }
2905
- callHook(vm, 'beforeMount');
2827
+ }
2906
2828
 
2907
- var updateComponent;
2908
- /* istanbul ignore if */
2909
- if (config.performance && mark) {
2910
- updateComponent = function () {
2911
- var name = vm._name;
2912
- var id = vm._uid;
2913
- var startTag = "vue-perf-start:" + id;
2914
- var endTag = "vue-perf-end:" + id;
2829
+ function markStaticNode (node, key, isOnce) {
2830
+ node.isStatic = true;
2831
+ node.key = key;
2832
+ node.isOnce = isOnce;
2833
+ }
2915
2834
 
2916
- mark(startTag);
2917
- var vnode = vm._render();
2918
- mark(endTag);
2919
- measure(("vue " + name + " render"), startTag, endTag);
2835
+ /* */
2920
2836
 
2921
- mark(startTag);
2922
- vm._update(vnode, hydrating);
2923
- mark(endTag);
2924
- measure(("vue " + name + " patch"), startTag, endTag);
2925
- };
2926
- } else {
2927
- updateComponent = function () {
2928
- vm._update(vm._render(), hydrating);
2929
- };
2837
+ function bindObjectListeners (data, value) {
2838
+ if (value) {
2839
+ if (!isPlainObject(value)) {
2840
+ warn(
2841
+ 'v-on without argument expects an Object value',
2842
+ this
2843
+ );
2844
+ } else {
2845
+ var on = data.on = data.on ? extend({}, data.on) : {};
2846
+ for (var key in value) {
2847
+ var existing = on[key];
2848
+ var ours = value[key];
2849
+ on[key] = existing ? [].concat(existing, ours) : ours;
2850
+ }
2851
+ }
2930
2852
  }
2853
+ return data
2854
+ }
2931
2855
 
2932
- // we set this to vm._watcher inside the watcher's constructor
2933
- // since the watcher's initial patch may call $forceUpdate (e.g. inside child
2934
- // component's mounted hook), which relies on vm._watcher being already defined
2935
- new Watcher(vm, updateComponent, noop, {
2936
- before: function before () {
2937
- if (vm._isMounted && !vm._isDestroyed) {
2938
- callHook(vm, 'beforeUpdate');
2856
+ /* */
2857
+
2858
+ function resolveScopedSlots (
2859
+ fns, // see flow/vnode
2860
+ hasDynamicKeys,
2861
+ res
2862
+ ) {
2863
+ res = res || { $stable: !hasDynamicKeys };
2864
+ for (var i = 0; i < fns.length; i++) {
2865
+ var slot = fns[i];
2866
+ if (Array.isArray(slot)) {
2867
+ resolveScopedSlots(slot, hasDynamicKeys, res);
2868
+ } else if (slot) {
2869
+ // marker for reverse proxying v-slot without scope on this.$slots
2870
+ if (slot.proxy) {
2871
+ slot.fn.proxy = true;
2939
2872
  }
2873
+ res[slot.key] = slot.fn;
2940
2874
  }
2941
- }, true /* isRenderWatcher */);
2942
- hydrating = false;
2943
-
2944
- // manually mounted instance, call mounted on self
2945
- // mounted is called for render-created child components in its inserted hook
2946
- if (vm.$vnode == null) {
2947
- vm._isMounted = true;
2948
- callHook(vm, 'mounted');
2949
2875
  }
2950
- return vm
2876
+ return res
2951
2877
  }
2952
2878
 
2953
- function updateChildComponent (
2954
- vm,
2955
- propsData,
2956
- listeners,
2957
- parentVnode,
2958
- renderChildren
2959
- ) {
2960
- {
2961
- isUpdatingChildComponent = true;
2879
+ /* */
2880
+
2881
+ function bindDynamicKeys (baseObj, values) {
2882
+ for (var i = 0; i < values.length; i += 2) {
2883
+ var key = values[i];
2884
+ if (typeof key === 'string' && key) {
2885
+ baseObj[values[i]] = values[i + 1];
2886
+ } else if (key !== '' && key !== null) {
2887
+ // null is a speical value for explicitly removing a binding
2888
+ warn(
2889
+ ("Invalid value for dynamic directive argument (expected string or null): " + key),
2890
+ this
2891
+ );
2892
+ }
2962
2893
  }
2894
+ return baseObj
2895
+ }
2963
2896
 
2964
- // determine whether component has slot children
2965
- // we need to do this before overwriting $options._renderChildren.
2897
+ // helper to dynamically append modifier runtime markers to event names.
2898
+ // ensure only append when value is already string, otherwise it will be cast
2899
+ // to string and cause the type check to miss.
2900
+ function prependModifier (value, symbol) {
2901
+ return typeof value === 'string' ? symbol + value : value
2902
+ }
2966
2903
 
2967
- // check if there are dynamic scopedSlots (hand-written or compiled but with
2968
- // dynamic slot names). Static scoped slots compiled from template has the
2969
- // "$stable" marker.
2970
- var hasDynamicScopedSlot = !!(
2971
- (parentVnode.data.scopedSlots && !parentVnode.data.scopedSlots.$stable) ||
2972
- (vm.$scopedSlots !== emptyObject && !vm.$scopedSlots.$stable)
2973
- );
2974
- // Any static slot children from the parent may have changed during parent's
2975
- // update. Dynamic scoped slots may also have changed. In such cases, a forced
2976
- // update is necessary to ensure correctness.
2977
- var needsForceUpdate = !!(
2978
- renderChildren || // has new static slots
2979
- vm.$options._renderChildren || // has old static slots
2980
- hasDynamicScopedSlot
2981
- );
2904
+ /* */
2982
2905
 
2983
- vm.$options._parentVnode = parentVnode;
2984
- vm.$vnode = parentVnode; // update vm's placeholder node without re-render
2906
+ function installRenderHelpers (target) {
2907
+ target._o = markOnce;
2908
+ target._n = toNumber;
2909
+ target._s = toString;
2910
+ target._l = renderList;
2911
+ target._t = renderSlot;
2912
+ target._q = looseEqual;
2913
+ target._i = looseIndexOf;
2914
+ target._m = renderStatic;
2915
+ target._f = resolveFilter;
2916
+ target._k = checkKeyCodes;
2917
+ target._b = bindObjectProps;
2918
+ target._v = createTextVNode;
2919
+ target._e = createEmptyVNode;
2920
+ target._u = resolveScopedSlots;
2921
+ target._g = bindObjectListeners;
2922
+ target._d = bindDynamicKeys;
2923
+ target._p = prependModifier;
2924
+ }
2985
2925
 
2986
- if (vm._vnode) { // update child tree's parent
2987
- vm._vnode.parent = parentVnode;
2988
- }
2989
- vm.$options._renderChildren = renderChildren;
2926
+ /* */
2990
2927
 
2991
- // update $attrs and $listeners hash
2992
- // these are also reactive so they may trigger child update if the child
2993
- // used them during render
2994
- vm.$attrs = parentVnode.data.attrs || emptyObject;
2995
- vm.$listeners = listeners || emptyObject;
2928
+ function FunctionalRenderContext (
2929
+ data,
2930
+ props,
2931
+ children,
2932
+ parent,
2933
+ Ctor
2934
+ ) {
2935
+ var this$1 = this;
2996
2936
 
2997
- // update props
2998
- if (propsData && vm.$options.props) {
2999
- toggleObserving(false);
3000
- var props = vm._props;
3001
- var propKeys = vm.$options._propKeys || [];
3002
- for (var i = 0; i < propKeys.length; i++) {
3003
- var key = propKeys[i];
3004
- var propOptions = vm.$options.props; // wtf flow?
3005
- props[key] = validateProp(key, propOptions, propsData, vm);
3006
- }
3007
- toggleObserving(true);
3008
- // keep a copy of raw propsData
3009
- vm.$options.propsData = propsData;
2937
+ var options = Ctor.options;
2938
+ // ensure the createElement function in functional components
2939
+ // gets a unique context - this is necessary for correct named slot check
2940
+ var contextVm;
2941
+ if (hasOwn(parent, '_uid')) {
2942
+ contextVm = Object.create(parent);
2943
+ // $flow-disable-line
2944
+ contextVm._original = parent;
2945
+ } else {
2946
+ // the context vm passed in is a functional context as well.
2947
+ // in this case we want to make sure we are able to get a hold to the
2948
+ // real context instance.
2949
+ contextVm = parent;
2950
+ // $flow-disable-line
2951
+ parent = parent._original;
3010
2952
  }
2953
+ var isCompiled = isTrue(options._compiled);
2954
+ var needNormalization = !isCompiled;
3011
2955
 
3012
- // update listeners
3013
- listeners = listeners || emptyObject;
3014
- var oldListeners = vm.$options._parentListeners;
3015
- vm.$options._parentListeners = listeners;
3016
- updateComponentListeners(vm, listeners, oldListeners);
2956
+ this.data = data;
2957
+ this.props = props;
2958
+ this.children = children;
2959
+ this.parent = parent;
2960
+ this.listeners = data.on || emptyObject;
2961
+ this.injections = resolveInject(options.inject, parent);
2962
+ this.slots = function () {
2963
+ if (!this$1.$slots) {
2964
+ normalizeScopedSlots(
2965
+ data.scopedSlots,
2966
+ this$1.$slots = resolveSlots(children, parent)
2967
+ );
2968
+ }
2969
+ return this$1.$slots
2970
+ };
3017
2971
 
3018
- // resolve slots + force update if has children
3019
- if (needsForceUpdate) {
3020
- vm.$slots = resolveSlots(renderChildren, parentVnode.context);
3021
- vm.$forceUpdate();
2972
+ Object.defineProperty(this, 'scopedSlots', ({
2973
+ enumerable: true,
2974
+ get: function get () {
2975
+ return normalizeScopedSlots(data.scopedSlots, this.slots())
2976
+ }
2977
+ }));
2978
+
2979
+ // support for compiled functional template
2980
+ if (isCompiled) {
2981
+ // exposing $options for renderStatic()
2982
+ this.$options = options;
2983
+ // pre-resolve slots for renderSlot()
2984
+ this.$slots = this.slots();
2985
+ this.$scopedSlots = normalizeScopedSlots(data.scopedSlots, this.$slots);
3022
2986
  }
3023
2987
 
3024
- {
3025
- isUpdatingChildComponent = false;
2988
+ if (options._scopeId) {
2989
+ this._c = function (a, b, c, d) {
2990
+ var vnode = createElement(contextVm, a, b, c, d, needNormalization);
2991
+ if (vnode && !Array.isArray(vnode)) {
2992
+ vnode.fnScopeId = options._scopeId;
2993
+ vnode.fnContext = parent;
2994
+ }
2995
+ return vnode
2996
+ };
2997
+ } else {
2998
+ this._c = function (a, b, c, d) { return createElement(contextVm, a, b, c, d, needNormalization); };
3026
2999
  }
3027
3000
  }
3028
3001
 
3029
- function isInInactiveTree (vm) {
3030
- while (vm && (vm = vm.$parent)) {
3031
- if (vm._inactive) { return true }
3032
- }
3033
- return false
3034
- }
3002
+ installRenderHelpers(FunctionalRenderContext.prototype);
3035
3003
 
3036
- function activateChildComponent (vm, direct) {
3037
- if (direct) {
3038
- vm._directInactive = false;
3039
- if (isInInactiveTree(vm)) {
3040
- return
3004
+ function createFunctionalComponent (
3005
+ Ctor,
3006
+ propsData,
3007
+ data,
3008
+ contextVm,
3009
+ children
3010
+ ) {
3011
+ var options = Ctor.options;
3012
+ var props = {};
3013
+ var propOptions = options.props;
3014
+ if (isDef(propOptions)) {
3015
+ for (var key in propOptions) {
3016
+ props[key] = validateProp(key, propOptions, propsData || emptyObject);
3041
3017
  }
3042
- } else if (vm._directInactive) {
3043
- return
3018
+ } else {
3019
+ if (isDef(data.attrs)) { mergeProps(props, data.attrs); }
3020
+ if (isDef(data.props)) { mergeProps(props, data.props); }
3044
3021
  }
3045
- if (vm._inactive || vm._inactive === null) {
3046
- vm._inactive = false;
3047
- for (var i = 0; i < vm.$children.length; i++) {
3048
- activateChildComponent(vm.$children[i]);
3022
+
3023
+ var renderContext = new FunctionalRenderContext(
3024
+ data,
3025
+ props,
3026
+ children,
3027
+ contextVm,
3028
+ Ctor
3029
+ );
3030
+
3031
+ var vnode = options.render.call(null, renderContext._c, renderContext);
3032
+
3033
+ if (vnode instanceof VNode) {
3034
+ return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext)
3035
+ } else if (Array.isArray(vnode)) {
3036
+ var vnodes = normalizeChildren(vnode) || [];
3037
+ var res = new Array(vnodes.length);
3038
+ for (var i = 0; i < vnodes.length; i++) {
3039
+ res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
3049
3040
  }
3050
- callHook(vm, 'activated');
3041
+ return res
3051
3042
  }
3052
3043
  }
3053
3044
 
3054
- function deactivateChildComponent (vm, direct) {
3055
- if (direct) {
3056
- vm._directInactive = true;
3057
- if (isInInactiveTree(vm)) {
3058
- return
3059
- }
3045
+ function cloneAndMarkFunctionalResult (vnode, data, contextVm, options, renderContext) {
3046
+ // #7817 clone node before setting fnContext, otherwise if the node is reused
3047
+ // (e.g. it was from a cached normal slot) the fnContext causes named slots
3048
+ // that should not be matched to match.
3049
+ var clone = cloneVNode(vnode);
3050
+ clone.fnContext = contextVm;
3051
+ clone.fnOptions = options;
3052
+ {
3053
+ (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext = renderContext;
3060
3054
  }
3061
- if (!vm._inactive) {
3062
- vm._inactive = true;
3063
- for (var i = 0; i < vm.$children.length; i++) {
3064
- deactivateChildComponent(vm.$children[i]);
3065
- }
3066
- callHook(vm, 'deactivated');
3055
+ if (data.slot) {
3056
+ (clone.data || (clone.data = {})).slot = data.slot;
3067
3057
  }
3058
+ return clone
3068
3059
  }
3069
3060
 
3070
- function callHook (vm, hook) {
3071
- // #7573 disable dep collection when invoking lifecycle hooks
3072
- pushTarget();
3073
- var handlers = vm.$options[hook];
3074
- var info = hook + " hook";
3075
- if (handlers) {
3076
- for (var i = 0, j = handlers.length; i < j; i++) {
3077
- invokeWithErrorHandling(handlers[i], vm, null, vm, info);
3078
- }
3079
- }
3080
- if (vm._hasHookEvent) {
3081
- vm.$emit('hook:' + hook);
3061
+ function mergeProps (to, from) {
3062
+ for (var key in from) {
3063
+ to[camelize(key)] = from[key];
3082
3064
  }
3083
- popTarget();
3084
3065
  }
3085
3066
 
3086
3067
  /* */
3087
3068
 
3088
- var MAX_UPDATE_COUNT = 100;
3069
+ /* */
3089
3070
 
3090
- var queue = [];
3091
- var activatedChildren = [];
3092
- var has = {};
3093
- var circular = {};
3094
- var waiting = false;
3095
- var flushing = false;
3096
- var index = 0;
3071
+ /* */
3097
3072
 
3098
- /**
3099
- * Reset the scheduler's state.
3100
- */
3101
- function resetSchedulerState () {
3102
- index = queue.length = activatedChildren.length = 0;
3103
- has = {};
3104
- {
3105
- circular = {};
3106
- }
3107
- waiting = flushing = false;
3108
- }
3073
+ /* */
3109
3074
 
3110
- // Async edge case #6566 requires saving the timestamp when event listeners are
3111
- // attached. However, calling performance.now() has a perf overhead especially
3112
- // if the page has thousands of event listeners. Instead, we take a timestamp
3113
- // every time the scheduler flushes and use that for all event listeners
3114
- // attached during that flush.
3115
- var currentFlushTimestamp = 0;
3075
+ // inline hooks to be invoked on component VNodes during patch
3076
+ var componentVNodeHooks = {
3077
+ init: function init (vnode, hydrating) {
3078
+ if (
3079
+ vnode.componentInstance &&
3080
+ !vnode.componentInstance._isDestroyed &&
3081
+ vnode.data.keepAlive
3082
+ ) {
3083
+ // kept-alive components, treat as a patch
3084
+ var mountedNode = vnode; // work around flow
3085
+ componentVNodeHooks.prepatch(mountedNode, mountedNode);
3086
+ } else {
3087
+ var child = vnode.componentInstance = createComponentInstanceForVnode(
3088
+ vnode,
3089
+ activeInstance
3090
+ );
3091
+ child.$mount(hydrating ? vnode.elm : undefined, hydrating);
3092
+ }
3093
+ },
3116
3094
 
3117
- // Async edge case fix requires storing an event listener's attach timestamp.
3118
- var getNow = Date.now;
3095
+ prepatch: function prepatch (oldVnode, vnode) {
3096
+ var options = vnode.componentOptions;
3097
+ var child = vnode.componentInstance = oldVnode.componentInstance;
3098
+ updateChildComponent(
3099
+ child,
3100
+ options.propsData, // updated props
3101
+ options.listeners, // updated listeners
3102
+ vnode, // new parent vnode
3103
+ options.children // new children
3104
+ );
3105
+ },
3119
3106
 
3120
- // Determine what event timestamp the browser is using. Annoyingly, the
3121
- // timestamp can either be hi-res ( relative to poge load) or low-res
3122
- // (relative to UNIX epoch), so in order to compare time we have to use the
3123
- // same timestamp type when saving the flush timestamp.
3124
- if (inBrowser && getNow() > document.createEvent('Event').timeStamp) {
3125
- // if the low-res timestamp which is bigger than the event timestamp
3126
- // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
3127
- // and we need to use the hi-res version for event listeners as well.
3128
- getNow = function () { return performance.now(); };
3129
- }
3107
+ insert: function insert (vnode) {
3108
+ var context = vnode.context;
3109
+ var componentInstance = vnode.componentInstance;
3110
+ if (!componentInstance._isMounted) {
3111
+ componentInstance._isMounted = true;
3112
+ callHook(componentInstance, 'mounted');
3113
+ }
3114
+ if (vnode.data.keepAlive) {
3115
+ if (context._isMounted) {
3116
+ // vue-router#1212
3117
+ // During updates, a kept-alive component's child components may
3118
+ // change, so directly walking the tree here may call activated hooks
3119
+ // on incorrect children. Instead we push them into a queue which will
3120
+ // be processed after the whole patch process ended.
3121
+ queueActivatedComponent(componentInstance);
3122
+ } else {
3123
+ activateChildComponent(componentInstance, true /* direct */);
3124
+ }
3125
+ }
3126
+ },
3130
3127
 
3131
- /**
3132
- * Flush both queues and run the watchers.
3133
- */
3134
- function flushSchedulerQueue () {
3135
- currentFlushTimestamp = getNow();
3136
- flushing = true;
3137
- var watcher, id;
3128
+ destroy: function destroy (vnode) {
3129
+ var componentInstance = vnode.componentInstance;
3130
+ if (!componentInstance._isDestroyed) {
3131
+ if (!vnode.data.keepAlive) {
3132
+ componentInstance.$destroy();
3133
+ } else {
3134
+ deactivateChildComponent(componentInstance, true /* direct */);
3135
+ }
3136
+ }
3137
+ }
3138
+ };
3138
3139
 
3139
- // Sort queue before flush.
3140
- // This ensures that:
3141
- // 1. Components are updated from parent to child. (because parent is always
3142
- // created before the child)
3143
- // 2. A component's user watchers are run before its render watcher (because
3144
- // user watchers are created before the render watcher)
3145
- // 3. If a component is destroyed during a parent component's watcher run,
3146
- // its watchers can be skipped.
3147
- queue.sort(function (a, b) { return a.id - b.id; });
3140
+ var hooksToMerge = Object.keys(componentVNodeHooks);
3148
3141
 
3149
- // do not cache length because more watchers might be pushed
3150
- // as we run existing watchers
3151
- for (index = 0; index < queue.length; index++) {
3152
- watcher = queue[index];
3153
- if (watcher.before) {
3154
- watcher.before();
3155
- }
3156
- id = watcher.id;
3157
- has[id] = null;
3158
- watcher.run();
3159
- // in dev build, check and stop circular updates.
3160
- if (has[id] != null) {
3161
- circular[id] = (circular[id] || 0) + 1;
3162
- if (circular[id] > MAX_UPDATE_COUNT) {
3163
- warn(
3164
- 'You may have an infinite update loop ' + (
3165
- watcher.user
3166
- ? ("in watcher with expression \"" + (watcher.expression) + "\"")
3167
- : "in a component render function."
3168
- ),
3169
- watcher.vm
3170
- );
3171
- break
3172
- }
3142
+ function createComponent (
3143
+ Ctor,
3144
+ data,
3145
+ context,
3146
+ children,
3147
+ tag
3148
+ ) {
3149
+ if (isUndef(Ctor)) {
3150
+ return
3151
+ }
3152
+
3153
+ var baseCtor = context.$options._base;
3154
+
3155
+ // plain options object: turn it into a constructor
3156
+ if (isObject(Ctor)) {
3157
+ Ctor = baseCtor.extend(Ctor);
3158
+ }
3159
+
3160
+ // if at this stage it's not a constructor or an async component factory,
3161
+ // reject.
3162
+ if (typeof Ctor !== 'function') {
3163
+ {
3164
+ warn(("Invalid Component definition: " + (String(Ctor))), context);
3173
3165
  }
3166
+ return
3174
3167
  }
3175
3168
 
3176
- // keep copies of post queues before resetting state
3177
- var activatedQueue = activatedChildren.slice();
3178
- var updatedQueue = queue.slice();
3169
+ // async component
3170
+ var asyncFactory;
3171
+ if (isUndef(Ctor.cid)) {
3172
+ asyncFactory = Ctor;
3173
+ Ctor = resolveAsyncComponent(asyncFactory, baseCtor);
3174
+ if (Ctor === undefined) {
3175
+ // return a placeholder node for async component, which is rendered
3176
+ // as a comment node but preserves all the raw information for the node.
3177
+ // the information will be used for async server-rendering and hydration.
3178
+ return createAsyncPlaceholder(
3179
+ asyncFactory,
3180
+ data,
3181
+ context,
3182
+ children,
3183
+ tag
3184
+ )
3185
+ }
3186
+ }
3179
3187
 
3180
- resetSchedulerState();
3188
+ data = data || {};
3181
3189
 
3182
- // call component updated and activated hooks
3183
- callActivatedHooks(activatedQueue);
3184
- callUpdatedHooks(updatedQueue);
3190
+ // resolve constructor options in case global mixins are applied after
3191
+ // component constructor creation
3192
+ resolveConstructorOptions(Ctor);
3185
3193
 
3186
- // devtool hook
3187
- /* istanbul ignore if */
3188
- if (devtools && config.devtools) {
3189
- devtools.emit('flush');
3194
+ // transform component v-model data into props & events
3195
+ if (isDef(data.model)) {
3196
+ transformModel(Ctor.options, data);
3190
3197
  }
3191
- }
3192
3198
 
3193
- function callUpdatedHooks (queue) {
3194
- var i = queue.length;
3195
- while (i--) {
3196
- var watcher = queue[i];
3197
- var vm = watcher.vm;
3198
- if (vm._watcher === watcher && vm._isMounted && !vm._isDestroyed) {
3199
- callHook(vm, 'updated');
3199
+ // extract props
3200
+ var propsData = extractPropsFromVNodeData(data, Ctor, tag);
3201
+
3202
+ // functional component
3203
+ if (isTrue(Ctor.options.functional)) {
3204
+ return createFunctionalComponent(Ctor, propsData, data, context, children)
3205
+ }
3206
+
3207
+ // extract listeners, since these needs to be treated as
3208
+ // child component listeners instead of DOM listeners
3209
+ var listeners = data.on;
3210
+ // replace with listeners with .native modifier
3211
+ // so it gets processed during parent component patch.
3212
+ data.on = data.nativeOn;
3213
+
3214
+ if (isTrue(Ctor.options.abstract)) {
3215
+ // abstract components do not keep anything
3216
+ // other than props & listeners & slot
3217
+
3218
+ // work around flow
3219
+ var slot = data.slot;
3220
+ data = {};
3221
+ if (slot) {
3222
+ data.slot = slot;
3200
3223
  }
3201
3224
  }
3202
- }
3203
3225
 
3204
- /**
3205
- * Queue a kept-alive component that was activated during patch.
3206
- * The queue will be processed after the entire tree has been patched.
3207
- */
3208
- function queueActivatedComponent (vm) {
3209
- // setting _inactive to false here so that a render function can
3210
- // rely on checking whether it's in an inactive tree (e.g. router-view)
3211
- vm._inactive = false;
3212
- activatedChildren.push(vm);
3226
+ // install component management hooks onto the placeholder node
3227
+ installComponentHooks(data);
3228
+
3229
+ // return a placeholder vnode
3230
+ var name = Ctor.options.name || tag;
3231
+ var vnode = new VNode(
3232
+ ("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')),
3233
+ data, undefined, undefined, undefined, context,
3234
+ { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children },
3235
+ asyncFactory
3236
+ );
3237
+
3238
+ return vnode
3213
3239
  }
3214
3240
 
3215
- function callActivatedHooks (queue) {
3216
- for (var i = 0; i < queue.length; i++) {
3217
- queue[i]._inactive = true;
3218
- activateChildComponent(queue[i], true /* true */);
3241
+ function createComponentInstanceForVnode (
3242
+ vnode, // we know it's MountedComponentVNode but flow doesn't
3243
+ parent // activeInstance in lifecycle state
3244
+ ) {
3245
+ var options = {
3246
+ _isComponent: true,
3247
+ _parentVnode: vnode,
3248
+ parent: parent
3249
+ };
3250
+ // check inline-template render functions
3251
+ var inlineTemplate = vnode.data.inlineTemplate;
3252
+ if (isDef(inlineTemplate)) {
3253
+ options.render = inlineTemplate.render;
3254
+ options.staticRenderFns = inlineTemplate.staticRenderFns;
3219
3255
  }
3256
+ return new vnode.componentOptions.Ctor(options)
3220
3257
  }
3221
3258
 
3222
- /**
3223
- * Push a watcher into the watcher queue.
3224
- * Jobs with duplicate IDs will be skipped unless it's
3225
- * pushed when the queue is being flushed.
3226
- */
3227
- function queueWatcher (watcher) {
3228
- var id = watcher.id;
3229
- if (has[id] == null) {
3230
- has[id] = true;
3231
- if (!flushing) {
3232
- queue.push(watcher);
3233
- } else {
3234
- // if already flushing, splice the watcher based on its id
3235
- // if already past its id, it will be run next immediately.
3236
- var i = queue.length - 1;
3237
- while (i > index && queue[i].id > watcher.id) {
3238
- i--;
3239
- }
3240
- queue.splice(i + 1, 0, watcher);
3259
+ function installComponentHooks (data) {
3260
+ var hooks = data.hook || (data.hook = {});
3261
+ for (var i = 0; i < hooksToMerge.length; i++) {
3262
+ var key = hooksToMerge[i];
3263
+ var existing = hooks[key];
3264
+ var toMerge = componentVNodeHooks[key];
3265
+ if (existing !== toMerge && !(existing && existing._merged)) {
3266
+ hooks[key] = existing ? mergeHook$1(toMerge, existing) : toMerge;
3241
3267
  }
3242
- // queue the flush
3243
- if (!waiting) {
3244
- waiting = true;
3268
+ }
3269
+ }
3245
3270
 
3246
- if (!config.async) {
3247
- flushSchedulerQueue();
3248
- return
3249
- }
3250
- nextTick(flushSchedulerQueue);
3271
+ function mergeHook$1 (f1, f2) {
3272
+ var merged = function (a, b) {
3273
+ // flow complains about extra args which is why we use any
3274
+ f1(a, b);
3275
+ f2(a, b);
3276
+ };
3277
+ merged._merged = true;
3278
+ return merged
3279
+ }
3280
+
3281
+ // transform component v-model info (value and callback) into
3282
+ // prop and event handler respectively.
3283
+ function transformModel (options, data) {
3284
+ var prop = (options.model && options.model.prop) || 'value';
3285
+ var event = (options.model && options.model.event) || 'input'
3286
+ ;(data.attrs || (data.attrs = {}))[prop] = data.model.value;
3287
+ var on = data.on || (data.on = {});
3288
+ var existing = on[event];
3289
+ var callback = data.model.callback;
3290
+ if (isDef(existing)) {
3291
+ if (
3292
+ Array.isArray(existing)
3293
+ ? existing.indexOf(callback) === -1
3294
+ : existing !== callback
3295
+ ) {
3296
+ on[event] = [callback].concat(existing);
3251
3297
  }
3298
+ } else {
3299
+ on[event] = callback;
3252
3300
  }
3253
3301
  }
3254
3302
 
3255
3303
  /* */
3256
3304
 
3305
+ var SIMPLE_NORMALIZE = 1;
3306
+ var ALWAYS_NORMALIZE = 2;
3257
3307
 
3308
+ // wrapper function for providing a more flexible interface
3309
+ // without getting yelled at by flow
3310
+ function createElement (
3311
+ context,
3312
+ tag,
3313
+ data,
3314
+ children,
3315
+ normalizationType,
3316
+ alwaysNormalize
3317
+ ) {
3318
+ if (Array.isArray(data) || isPrimitive(data)) {
3319
+ normalizationType = children;
3320
+ children = data;
3321
+ data = undefined;
3322
+ }
3323
+ if (isTrue(alwaysNormalize)) {
3324
+ normalizationType = ALWAYS_NORMALIZE;
3325
+ }
3326
+ return _createElement(context, tag, data, children, normalizationType)
3327
+ }
3258
3328
 
3259
- var uid$1 = 0;
3260
-
3261
- /**
3262
- * A watcher parses an expression, collects dependencies,
3263
- * and fires callback when the expression value changes.
3264
- * This is used for both the $watch() api and directives.
3265
- */
3266
- var Watcher = function Watcher (
3267
- vm,
3268
- expOrFn,
3269
- cb,
3270
- options,
3271
- isRenderWatcher
3329
+ function _createElement (
3330
+ context,
3331
+ tag,
3332
+ data,
3333
+ children,
3334
+ normalizationType
3272
3335
  ) {
3273
- this.vm = vm;
3274
- if (isRenderWatcher) {
3275
- vm._watcher = this;
3336
+ if (isDef(data) && isDef((data).__ob__)) {
3337
+ warn(
3338
+ "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
3339
+ 'Always create fresh vnode data objects in each render!',
3340
+ context
3341
+ );
3342
+ return createEmptyVNode()
3276
3343
  }
3277
- vm._watchers.push(this);
3278
- // options
3279
- if (options) {
3280
- this.deep = !!options.deep;
3281
- this.user = !!options.user;
3282
- this.lazy = !!options.lazy;
3283
- this.sync = !!options.sync;
3284
- this.before = options.before;
3285
- } else {
3286
- this.deep = this.user = this.lazy = this.sync = false;
3344
+ // object syntax in v-bind
3345
+ if (isDef(data) && isDef(data.is)) {
3346
+ tag = data.is;
3347
+ }
3348
+ if (!tag) {
3349
+ // in case of component :is set to falsy value
3350
+ return createEmptyVNode()
3287
3351
  }
3288
- this.cb = cb;
3289
- this.id = ++uid$1; // uid for batching
3290
- this.active = true;
3291
- this.dirty = this.lazy; // for lazy watchers
3292
- this.deps = [];
3293
- this.newDeps = [];
3294
- this.depIds = new _Set();
3295
- this.newDepIds = new _Set();
3296
- this.expression = expOrFn.toString();
3297
- // parse expression for getter
3298
- if (typeof expOrFn === 'function') {
3299
- this.getter = expOrFn;
3300
- } else {
3301
- this.getter = parsePath(expOrFn);
3302
- if (!this.getter) {
3303
- this.getter = noop;
3352
+ // warn against non-primitive key
3353
+ if (isDef(data) && isDef(data.key) && !isPrimitive(data.key)
3354
+ ) {
3355
+ {
3304
3356
  warn(
3305
- "Failed watching path: \"" + expOrFn + "\" " +
3306
- 'Watcher only accepts simple dot-delimited paths. ' +
3307
- 'For full control, use a function instead.',
3308
- vm
3357
+ 'Avoid using non-primitive value as key, ' +
3358
+ 'use string/number value instead.',
3359
+ context
3309
3360
  );
3310
3361
  }
3311
3362
  }
3312
- this.value = this.lazy
3313
- ? undefined
3314
- : this.get();
3315
- };
3316
-
3317
- /**
3318
- * Evaluate the getter, and re-collect dependencies.
3319
- */
3320
- Watcher.prototype.get = function get () {
3321
- pushTarget(this);
3322
- var value;
3323
- var vm = this.vm;
3324
- try {
3325
- value = this.getter.call(vm, vm);
3326
- } catch (e) {
3327
- if (this.user) {
3328
- handleError(e, vm, ("getter for watcher \"" + (this.expression) + "\""));
3363
+ // support single function children as default scoped slot
3364
+ if (Array.isArray(children) &&
3365
+ typeof children[0] === 'function'
3366
+ ) {
3367
+ data = data || {};
3368
+ data.scopedSlots = { default: children[0] };
3369
+ children.length = 0;
3370
+ }
3371
+ if (normalizationType === ALWAYS_NORMALIZE) {
3372
+ children = normalizeChildren(children);
3373
+ } else if (normalizationType === SIMPLE_NORMALIZE) {
3374
+ children = simpleNormalizeChildren(children);
3375
+ }
3376
+ var vnode, ns;
3377
+ if (typeof tag === 'string') {
3378
+ var Ctor;
3379
+ ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
3380
+ if (config.isReservedTag(tag)) {
3381
+ // platform built-in elements
3382
+ vnode = new VNode(
3383
+ config.parsePlatformTagName(tag), data, children,
3384
+ undefined, undefined, context
3385
+ );
3386
+ } else if ((!data || !data.pre) && isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {
3387
+ // component
3388
+ vnode = createComponent(Ctor, data, context, children, tag);
3329
3389
  } else {
3330
- throw e
3331
- }
3332
- } finally {
3333
- // "touch" every property so they are all tracked as
3334
- // dependencies for deep watching
3335
- if (this.deep) {
3336
- traverse(value);
3390
+ // unknown or unlisted namespaced elements
3391
+ // check at runtime because it may get assigned a namespace when its
3392
+ // parent normalizes children
3393
+ vnode = new VNode(
3394
+ tag, data, children,
3395
+ undefined, undefined, context
3396
+ );
3337
3397
  }
3338
- popTarget();
3339
- this.cleanupDeps();
3398
+ } else {
3399
+ // direct component options / constructor
3400
+ vnode = createComponent(tag, data, context, children);
3340
3401
  }
3341
- return value
3342
- };
3402
+ if (Array.isArray(vnode)) {
3403
+ return vnode
3404
+ } else if (isDef(vnode)) {
3405
+ if (isDef(ns)) { applyNS(vnode, ns); }
3406
+ if (isDef(data)) { registerDeepBindings(data); }
3407
+ return vnode
3408
+ } else {
3409
+ return createEmptyVNode()
3410
+ }
3411
+ }
3343
3412
 
3344
- /**
3345
- * Add a dependency to this directive.
3346
- */
3347
- Watcher.prototype.addDep = function addDep (dep) {
3348
- var id = dep.id;
3349
- if (!this.newDepIds.has(id)) {
3350
- this.newDepIds.add(id);
3351
- this.newDeps.push(dep);
3352
- if (!this.depIds.has(id)) {
3353
- dep.addSub(this);
3413
+ function applyNS (vnode, ns, force) {
3414
+ vnode.ns = ns;
3415
+ if (vnode.tag === 'foreignObject') {
3416
+ // use default namespace inside foreignObject
3417
+ ns = undefined;
3418
+ force = true;
3419
+ }
3420
+ if (isDef(vnode.children)) {
3421
+ for (var i = 0, l = vnode.children.length; i < l; i++) {
3422
+ var child = vnode.children[i];
3423
+ if (isDef(child.tag) && (
3424
+ isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
3425
+ applyNS(child, ns, force);
3426
+ }
3354
3427
  }
3355
3428
  }
3356
- };
3429
+ }
3357
3430
 
3358
- /**
3359
- * Clean up for dependency collection.
3360
- */
3361
- Watcher.prototype.cleanupDeps = function cleanupDeps () {
3362
- var i = this.deps.length;
3363
- while (i--) {
3364
- var dep = this.deps[i];
3365
- if (!this.newDepIds.has(dep.id)) {
3366
- dep.removeSub(this);
3367
- }
3431
+ // ref #5318
3432
+ // necessary to ensure parent re-render when deep bindings like :style and
3433
+ // :class are used on slot nodes
3434
+ function registerDeepBindings (data) {
3435
+ if (isObject(data.style)) {
3436
+ traverse(data.style);
3368
3437
  }
3369
- var tmp = this.depIds;
3370
- this.depIds = this.newDepIds;
3371
- this.newDepIds = tmp;
3372
- this.newDepIds.clear();
3373
- tmp = this.deps;
3374
- this.deps = this.newDeps;
3375
- this.newDeps = tmp;
3376
- this.newDeps.length = 0;
3377
- };
3438
+ if (isObject(data.class)) {
3439
+ traverse(data.class);
3440
+ }
3441
+ }
3442
+
3443
+ /* */
3444
+
3445
+ function initRender (vm) {
3446
+ vm._vnode = null; // the root of the child tree
3447
+ vm._staticTrees = null; // v-once cached trees
3448
+ var options = vm.$options;
3449
+ var parentVnode = vm.$vnode = options._parentVnode; // the placeholder node in parent tree
3450
+ var renderContext = parentVnode && parentVnode.context;
3451
+ vm.$slots = resolveSlots(options._renderChildren, renderContext);
3452
+ vm.$scopedSlots = emptyObject;
3453
+ // bind the createElement fn to this instance
3454
+ // so that we get proper render context inside it.
3455
+ // args order: tag, data, children, normalizationType, alwaysNormalize
3456
+ // internal version is used by render functions compiled from templates
3457
+ vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); };
3458
+ // normalization is always applied for the public version, used in
3459
+ // user-written render functions.
3460
+ vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); };
3461
+
3462
+ // $attrs & $listeners are exposed for easier HOC creation.
3463
+ // they need to be reactive so that HOCs using them are always updated
3464
+ var parentData = parentVnode && parentVnode.data;
3378
3465
 
3379
- /**
3380
- * Subscriber interface.
3381
- * Will be called when a dependency changes.
3382
- */
3383
- Watcher.prototype.update = function update () {
3384
3466
  /* istanbul ignore else */
3385
- if (this.lazy) {
3386
- this.dirty = true;
3387
- } else if (this.sync) {
3388
- this.run();
3389
- } else {
3390
- queueWatcher(this);
3467
+ {
3468
+ defineReactive$$1(vm, '$attrs', parentData && parentData.attrs || emptyObject, function () {
3469
+ !isUpdatingChildComponent && warn("$attrs is readonly.", vm);
3470
+ }, true);
3471
+ defineReactive$$1(vm, '$listeners', options._parentListeners || emptyObject, function () {
3472
+ !isUpdatingChildComponent && warn("$listeners is readonly.", vm);
3473
+ }, true);
3391
3474
  }
3392
- };
3475
+ }
3393
3476
 
3394
- /**
3395
- * Scheduler job interface.
3396
- * Will be called by the scheduler.
3397
- */
3398
- Watcher.prototype.run = function run () {
3399
- if (this.active) {
3400
- var value = this.get();
3401
- if (
3402
- value !== this.value ||
3403
- // Deep watchers and watchers on Object/Arrays should fire even
3404
- // when the value is the same, because the value may
3405
- // have mutated.
3406
- isObject(value) ||
3407
- this.deep
3408
- ) {
3409
- // set new value
3410
- var oldValue = this.value;
3411
- this.value = value;
3412
- if (this.user) {
3477
+ var currentRenderingInstance = null;
3478
+
3479
+ function renderMixin (Vue) {
3480
+ // install runtime convenience helpers
3481
+ installRenderHelpers(Vue.prototype);
3482
+
3483
+ Vue.prototype.$nextTick = function (fn) {
3484
+ return nextTick(fn, this)
3485
+ };
3486
+
3487
+ Vue.prototype._render = function () {
3488
+ var vm = this;
3489
+ var ref = vm.$options;
3490
+ var render = ref.render;
3491
+ var _parentVnode = ref._parentVnode;
3492
+
3493
+ if (_parentVnode) {
3494
+ vm.$scopedSlots = normalizeScopedSlots(
3495
+ _parentVnode.data.scopedSlots,
3496
+ vm.$slots,
3497
+ vm.$scopedSlots
3498
+ );
3499
+ }
3500
+
3501
+ // set parent vnode. this allows render functions to have access
3502
+ // to the data on the placeholder node.
3503
+ vm.$vnode = _parentVnode;
3504
+ // render self
3505
+ var vnode;
3506
+ try {
3507
+ // There's no need to maintain a stack becaues all render fns are called
3508
+ // separately from one another. Nested component's render fns are called
3509
+ // when parent component is patched.
3510
+ currentRenderingInstance = vm;
3511
+ vnode = render.call(vm._renderProxy, vm.$createElement);
3512
+ } catch (e) {
3513
+ handleError(e, vm, "render");
3514
+ // return error render result,
3515
+ // or previous vnode to prevent render error causing blank component
3516
+ /* istanbul ignore else */
3517
+ if (vm.$options.renderError) {
3413
3518
  try {
3414
- this.cb.call(this.vm, value, oldValue);
3519
+ vnode = vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e);
3415
3520
  } catch (e) {
3416
- handleError(e, this.vm, ("callback for watcher \"" + (this.expression) + "\""));
3521
+ handleError(e, vm, "renderError");
3522
+ vnode = vm._vnode;
3417
3523
  }
3418
3524
  } else {
3419
- this.cb.call(this.vm, value, oldValue);
3525
+ vnode = vm._vnode;
3420
3526
  }
3527
+ } finally {
3528
+ currentRenderingInstance = null;
3421
3529
  }
3422
- }
3423
- };
3424
-
3425
- /**
3426
- * Evaluate the value of the watcher.
3427
- * This only gets called for lazy watchers.
3428
- */
3429
- Watcher.prototype.evaluate = function evaluate () {
3430
- this.value = this.get();
3431
- this.dirty = false;
3432
- };
3433
-
3434
- /**
3435
- * Depend on all deps collected by this watcher.
3436
- */
3437
- Watcher.prototype.depend = function depend () {
3438
- var i = this.deps.length;
3439
- while (i--) {
3440
- this.deps[i].depend();
3441
- }
3442
- };
3443
-
3444
- /**
3445
- * Remove self from all dependencies' subscriber list.
3446
- */
3447
- Watcher.prototype.teardown = function teardown () {
3448
- if (this.active) {
3449
- // remove self from vm's watcher list
3450
- // this is a somewhat expensive operation so we skip it
3451
- // if the vm is being destroyed.
3452
- if (!this.vm._isBeingDestroyed) {
3453
- remove(this.vm._watchers, this);
3530
+ // if the returned array contains only a single node, allow it
3531
+ if (Array.isArray(vnode) && vnode.length === 1) {
3532
+ vnode = vnode[0];
3454
3533
  }
3455
- var i = this.deps.length;
3456
- while (i--) {
3457
- this.deps[i].removeSub(this);
3534
+ // return empty vnode in case the render function errored out
3535
+ if (!(vnode instanceof VNode)) {
3536
+ if (Array.isArray(vnode)) {
3537
+ warn(
3538
+ 'Multiple root nodes returned from render function. Render function ' +
3539
+ 'should return a single root node.',
3540
+ vm
3541
+ );
3542
+ }
3543
+ vnode = createEmptyVNode();
3458
3544
  }
3459
- this.active = false;
3460
- }
3461
- };
3545
+ // set parent
3546
+ vnode.parent = _parentVnode;
3547
+ return vnode
3548
+ };
3549
+ }
3462
3550
 
3463
3551
  /* */
3464
3552
 
3465
- var sharedPropertyDefinition = {
3466
- enumerable: true,
3467
- configurable: true,
3468
- get: noop,
3469
- set: noop
3470
- };
3553
+ function ensureCtor (comp, base) {
3554
+ if (
3555
+ comp.__esModule ||
3556
+ (hasSymbol && comp[Symbol.toStringTag] === 'Module')
3557
+ ) {
3558
+ comp = comp.default;
3559
+ }
3560
+ return isObject(comp)
3561
+ ? base.extend(comp)
3562
+ : comp
3563
+ }
3471
3564
 
3472
- function proxy (target, sourceKey, key) {
3473
- sharedPropertyDefinition.get = function proxyGetter () {
3474
- return this[sourceKey][key]
3475
- };
3476
- sharedPropertyDefinition.set = function proxySetter (val) {
3477
- this[sourceKey][key] = val;
3478
- };
3479
- Object.defineProperty(target, key, sharedPropertyDefinition);
3565
+ function createAsyncPlaceholder (
3566
+ factory,
3567
+ data,
3568
+ context,
3569
+ children,
3570
+ tag
3571
+ ) {
3572
+ var node = createEmptyVNode();
3573
+ node.asyncFactory = factory;
3574
+ node.asyncMeta = { data: data, context: context, children: children, tag: tag };
3575
+ return node
3480
3576
  }
3481
3577
 
3482
- function initState (vm) {
3483
- vm._watchers = [];
3484
- var opts = vm.$options;
3485
- if (opts.props) { initProps(vm, opts.props); }
3486
- if (opts.methods) { initMethods(vm, opts.methods); }
3487
- if (opts.data) {
3488
- initData(vm);
3489
- } else {
3490
- observe(vm._data = {}, true /* asRootData */);
3578
+ function resolveAsyncComponent (
3579
+ factory,
3580
+ baseCtor
3581
+ ) {
3582
+ if (isTrue(factory.error) && isDef(factory.errorComp)) {
3583
+ return factory.errorComp
3491
3584
  }
3492
- if (opts.computed) { initComputed(vm, opts.computed); }
3493
- if (opts.watch && opts.watch !== nativeWatch) {
3494
- initWatch(vm, opts.watch);
3585
+
3586
+ if (isDef(factory.resolved)) {
3587
+ return factory.resolved
3495
3588
  }
3496
- }
3497
3589
 
3498
- function initProps (vm, propsOptions) {
3499
- var propsData = vm.$options.propsData || {};
3500
- var props = vm._props = {};
3501
- // cache prop keys so that future props updates can iterate using Array
3502
- // instead of dynamic object key enumeration.
3503
- var keys = vm.$options._propKeys = [];
3504
- var isRoot = !vm.$parent;
3505
- // root instance props should be converted
3506
- if (!isRoot) {
3507
- toggleObserving(false);
3590
+ if (isTrue(factory.loading) && isDef(factory.loadingComp)) {
3591
+ return factory.loadingComp
3508
3592
  }
3509
- var loop = function ( key ) {
3510
- keys.push(key);
3511
- var value = validateProp(key, propsOptions, propsData, vm);
3512
- /* istanbul ignore else */
3513
- {
3514
- var hyphenatedKey = hyphenate(key);
3515
- if (isReservedAttribute(hyphenatedKey) ||
3516
- config.isReservedAttr(hyphenatedKey)) {
3517
- warn(
3518
- ("\"" + hyphenatedKey + "\" is a reserved attribute and cannot be used as component prop."),
3519
- vm
3520
- );
3593
+
3594
+ var owner = currentRenderingInstance;
3595
+ if (isDef(factory.owners)) {
3596
+ // already pending
3597
+ factory.owners.push(owner);
3598
+ } else {
3599
+ var owners = factory.owners = [owner];
3600
+ var sync = true;
3601
+
3602
+ var forceRender = function (renderCompleted) {
3603
+ for (var i = 0, l = owners.length; i < l; i++) {
3604
+ (owners[i]).$forceUpdate();
3521
3605
  }
3522
- defineReactive$$1(props, key, value, function () {
3523
- if (!isRoot && !isUpdatingChildComponent) {
3524
- warn(
3525
- "Avoid mutating a prop directly since the value will be " +
3526
- "overwritten whenever the parent component re-renders. " +
3527
- "Instead, use a data or computed property based on the prop's " +
3528
- "value. Prop being mutated: \"" + key + "\"",
3529
- vm
3530
- );
3531
- }
3532
- });
3533
- }
3534
- // static props are already proxied on the component's prototype
3535
- // during Vue.extend(). We only need to proxy props defined at
3536
- // instantiation here.
3537
- if (!(key in vm)) {
3538
- proxy(vm, "_props", key);
3539
- }
3540
- };
3541
3606
 
3542
- for (var key in propsOptions) loop( key );
3543
- toggleObserving(true);
3544
- }
3607
+ if (renderCompleted) {
3608
+ owners.length = 0;
3609
+ }
3610
+ };
3545
3611
 
3546
- function initData (vm) {
3547
- var data = vm.$options.data;
3548
- data = vm._data = typeof data === 'function'
3549
- ? getData(data, vm)
3550
- : data || {};
3551
- if (!isPlainObject(data)) {
3552
- data = {};
3553
- warn(
3554
- 'data functions should return an object:\n' +
3555
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
3556
- vm
3557
- );
3558
- }
3559
- // proxy data on instance
3560
- var keys = Object.keys(data);
3561
- var props = vm.$options.props;
3562
- var methods = vm.$options.methods;
3563
- var i = keys.length;
3564
- while (i--) {
3565
- var key = keys[i];
3566
- {
3567
- if (methods && hasOwn(methods, key)) {
3568
- warn(
3569
- ("Method \"" + key + "\" has already been defined as a data property."),
3570
- vm
3571
- );
3612
+ var resolve = once(function (res) {
3613
+ // cache resolved
3614
+ factory.resolved = ensureCtor(res, baseCtor);
3615
+ // invoke callbacks only if this is not a synchronous resolve
3616
+ // (async resolves are shimmed as synchronous during SSR)
3617
+ if (!sync) {
3618
+ forceRender(true);
3619
+ } else {
3620
+ owners.length = 0;
3572
3621
  }
3573
- }
3574
- if (props && hasOwn(props, key)) {
3622
+ });
3623
+
3624
+ var reject = once(function (reason) {
3575
3625
  warn(
3576
- "The data property \"" + key + "\" is already declared as a prop. " +
3577
- "Use prop default value instead.",
3578
- vm
3626
+ "Failed to resolve async component: " + (String(factory)) +
3627
+ (reason ? ("\nReason: " + reason) : '')
3579
3628
  );
3580
- } else if (!isReserved(key)) {
3581
- proxy(vm, "_data", key);
3629
+ if (isDef(factory.errorComp)) {
3630
+ factory.error = true;
3631
+ forceRender(true);
3632
+ }
3633
+ });
3634
+
3635
+ var res = factory(resolve, reject);
3636
+
3637
+ if (isObject(res)) {
3638
+ if (isPromise(res)) {
3639
+ // () => Promise
3640
+ if (isUndef(factory.resolved)) {
3641
+ res.then(resolve, reject);
3642
+ }
3643
+ } else if (isPromise(res.component)) {
3644
+ res.component.then(resolve, reject);
3645
+
3646
+ if (isDef(res.error)) {
3647
+ factory.errorComp = ensureCtor(res.error, baseCtor);
3648
+ }
3649
+
3650
+ if (isDef(res.loading)) {
3651
+ factory.loadingComp = ensureCtor(res.loading, baseCtor);
3652
+ if (res.delay === 0) {
3653
+ factory.loading = true;
3654
+ } else {
3655
+ setTimeout(function () {
3656
+ if (isUndef(factory.resolved) && isUndef(factory.error)) {
3657
+ factory.loading = true;
3658
+ forceRender(false);
3659
+ }
3660
+ }, res.delay || 200);
3661
+ }
3662
+ }
3663
+
3664
+ if (isDef(res.timeout)) {
3665
+ setTimeout(function () {
3666
+ if (isUndef(factory.resolved)) {
3667
+ reject(
3668
+ "timeout (" + (res.timeout) + "ms)"
3669
+ );
3670
+ }
3671
+ }, res.timeout);
3672
+ }
3673
+ }
3582
3674
  }
3583
- }
3584
- // observe data
3585
- observe(data, true /* asRootData */);
3586
- }
3587
3675
 
3588
- function getData (data, vm) {
3589
- // #7573 disable dep collection when invoking data getters
3590
- pushTarget();
3591
- try {
3592
- return data.call(vm, vm)
3593
- } catch (e) {
3594
- handleError(e, vm, "data()");
3595
- return {}
3596
- } finally {
3597
- popTarget();
3676
+ sync = false;
3677
+ // return in case resolved synchronously
3678
+ return factory.loading
3679
+ ? factory.loadingComp
3680
+ : factory.resolved
3598
3681
  }
3599
3682
  }
3600
3683
 
3601
- var computedWatcherOptions = { lazy: true };
3602
-
3603
- function initComputed (vm, computed) {
3604
- // $flow-disable-line
3605
- var watchers = vm._computedWatchers = Object.create(null);
3606
- // computed properties are just getters during SSR
3607
- var isSSR = isServerRendering();
3684
+ /* */
3608
3685
 
3609
- for (var key in computed) {
3610
- var userDef = computed[key];
3611
- var getter = typeof userDef === 'function' ? userDef : userDef.get;
3612
- if (getter == null) {
3613
- warn(
3614
- ("Getter is missing for computed property \"" + key + "\"."),
3615
- vm
3616
- );
3617
- }
3686
+ function isAsyncPlaceholder (node) {
3687
+ return node.isComment && node.asyncFactory
3688
+ }
3618
3689
 
3619
- if (!isSSR) {
3620
- // create internal watcher for the computed property.
3621
- watchers[key] = new Watcher(
3622
- vm,
3623
- getter || noop,
3624
- noop,
3625
- computedWatcherOptions
3626
- );
3627
- }
3690
+ /* */
3628
3691
 
3629
- // component-defined computed properties are already defined on the
3630
- // component prototype. We only need to define computed properties defined
3631
- // at instantiation here.
3632
- if (!(key in vm)) {
3633
- defineComputed(vm, key, userDef);
3634
- } else {
3635
- if (key in vm.$data) {
3636
- warn(("The computed property \"" + key + "\" is already defined in data."), vm);
3637
- } else if (vm.$options.props && key in vm.$options.props) {
3638
- warn(("The computed property \"" + key + "\" is already defined as a prop."), vm);
3692
+ function getFirstComponentChild (children) {
3693
+ if (Array.isArray(children)) {
3694
+ for (var i = 0; i < children.length; i++) {
3695
+ var c = children[i];
3696
+ if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) {
3697
+ return c
3639
3698
  }
3640
3699
  }
3641
3700
  }
3642
3701
  }
3643
3702
 
3644
- function defineComputed (
3645
- target,
3646
- key,
3647
- userDef
3648
- ) {
3649
- var shouldCache = !isServerRendering();
3650
- if (typeof userDef === 'function') {
3651
- sharedPropertyDefinition.get = shouldCache
3652
- ? createComputedGetter(key)
3653
- : createGetterInvoker(userDef);
3654
- sharedPropertyDefinition.set = noop;
3655
- } else {
3656
- sharedPropertyDefinition.get = userDef.get
3657
- ? shouldCache && userDef.cache !== false
3658
- ? createComputedGetter(key)
3659
- : createGetterInvoker(userDef.get)
3660
- : noop;
3661
- sharedPropertyDefinition.set = userDef.set || noop;
3662
- }
3663
- if (sharedPropertyDefinition.set === noop) {
3664
- sharedPropertyDefinition.set = function () {
3665
- warn(
3666
- ("Computed property \"" + key + "\" was assigned to but it has no setter."),
3667
- this
3668
- );
3669
- };
3670
- }
3671
- Object.defineProperty(target, key, sharedPropertyDefinition);
3672
- }
3703
+ /* */
3673
3704
 
3674
- function createComputedGetter (key) {
3675
- return function computedGetter () {
3676
- var watcher = this._computedWatchers && this._computedWatchers[key];
3677
- if (watcher) {
3678
- if (watcher.dirty) {
3679
- watcher.evaluate();
3680
- }
3681
- if (Dep.target) {
3682
- watcher.depend();
3683
- }
3684
- return watcher.value
3685
- }
3705
+ /* */
3706
+
3707
+ function initEvents (vm) {
3708
+ vm._events = Object.create(null);
3709
+ vm._hasHookEvent = false;
3710
+ // init parent attached events
3711
+ var listeners = vm.$options._parentListeners;
3712
+ if (listeners) {
3713
+ updateComponentListeners(vm, listeners);
3686
3714
  }
3687
3715
  }
3688
3716
 
3689
- function createGetterInvoker(fn) {
3690
- return function computedGetter () {
3691
- return fn.call(this, this)
3692
- }
3717
+ var target;
3718
+
3719
+ function add (event, fn) {
3720
+ target.$on(event, fn);
3693
3721
  }
3694
3722
 
3695
- function initMethods (vm, methods) {
3696
- var props = vm.$options.props;
3697
- for (var key in methods) {
3698
- {
3699
- if (typeof methods[key] !== 'function') {
3700
- warn(
3701
- "Method \"" + key + "\" has type \"" + (typeof methods[key]) + "\" in the component definition. " +
3702
- "Did you reference the function correctly?",
3703
- vm
3704
- );
3705
- }
3706
- if (props && hasOwn(props, key)) {
3707
- warn(
3708
- ("Method \"" + key + "\" has already been defined as a prop."),
3709
- vm
3710
- );
3711
- }
3712
- if ((key in vm) && isReserved(key)) {
3713
- warn(
3714
- "Method \"" + key + "\" conflicts with an existing Vue instance method. " +
3715
- "Avoid defining component methods that start with _ or $."
3716
- );
3717
- }
3718
- }
3719
- vm[key] = typeof methods[key] !== 'function' ? noop : bind(methods[key], vm);
3720
- }
3723
+ function remove$1 (event, fn) {
3724
+ target.$off(event, fn);
3721
3725
  }
3722
3726
 
3723
- function initWatch (vm, watch) {
3724
- for (var key in watch) {
3725
- var handler = watch[key];
3726
- if (Array.isArray(handler)) {
3727
- for (var i = 0; i < handler.length; i++) {
3728
- createWatcher(vm, key, handler[i]);
3729
- }
3730
- } else {
3731
- createWatcher(vm, key, handler);
3727
+ function createOnceHandler (event, fn) {
3728
+ var _target = target;
3729
+ return function onceHandler () {
3730
+ var res = fn.apply(null, arguments);
3731
+ if (res !== null) {
3732
+ _target.$off(event, onceHandler);
3732
3733
  }
3733
3734
  }
3734
3735
  }
3735
3736
 
3736
- function createWatcher (
3737
+ function updateComponentListeners (
3737
3738
  vm,
3738
- expOrFn,
3739
- handler,
3740
- options
3739
+ listeners,
3740
+ oldListeners
3741
3741
  ) {
3742
- if (isPlainObject(handler)) {
3743
- options = handler;
3744
- handler = handler.handler;
3745
- }
3746
- if (typeof handler === 'string') {
3747
- handler = vm[handler];
3748
- }
3749
- return vm.$watch(expOrFn, handler, options)
3742
+ target = vm;
3743
+ updateListeners(listeners, oldListeners || {}, add, remove$1, createOnceHandler, vm);
3744
+ target = undefined;
3750
3745
  }
3751
3746
 
3752
- function stateMixin (Vue) {
3753
- // flow somehow has problems with directly declared definition object
3754
- // when using Object.defineProperty, so we have to procedurally build up
3755
- // the object here.
3756
- var dataDef = {};
3757
- dataDef.get = function () { return this._data };
3758
- var propsDef = {};
3759
- propsDef.get = function () { return this._props };
3760
- {
3761
- dataDef.set = function () {
3762
- warn(
3763
- 'Avoid replacing instance root $data. ' +
3764
- 'Use nested data properties instead.',
3765
- this
3766
- );
3767
- };
3768
- propsDef.set = function () {
3769
- warn("$props is readonly.", this);
3770
- };
3771
- }
3772
- Object.defineProperty(Vue.prototype, '$data', dataDef);
3773
- Object.defineProperty(Vue.prototype, '$props', propsDef);
3747
+ function eventsMixin (Vue) {
3748
+ var hookRE = /^hook:/;
3749
+ Vue.prototype.$on = function (event, fn) {
3750
+ var vm = this;
3751
+ if (Array.isArray(event)) {
3752
+ for (var i = 0, l = event.length; i < l; i++) {
3753
+ vm.$on(event[i], fn);
3754
+ }
3755
+ } else {
3756
+ (vm._events[event] || (vm._events[event] = [])).push(fn);
3757
+ // optimize hook:event cost by using a boolean flag marked at registration
3758
+ // instead of a hash lookup
3759
+ if (hookRE.test(event)) {
3760
+ vm._hasHookEvent = true;
3761
+ }
3762
+ }
3763
+ return vm
3764
+ };
3774
3765
 
3775
- Vue.prototype.$set = set;
3776
- Vue.prototype.$delete = del;
3766
+ Vue.prototype.$once = function (event, fn) {
3767
+ var vm = this;
3768
+ function on () {
3769
+ vm.$off(event, on);
3770
+ fn.apply(vm, arguments);
3771
+ }
3772
+ on.fn = fn;
3773
+ vm.$on(event, on);
3774
+ return vm
3775
+ };
3776
+
3777
+ Vue.prototype.$off = function (event, fn) {
3778
+ var vm = this;
3779
+ // all
3780
+ if (!arguments.length) {
3781
+ vm._events = Object.create(null);
3782
+ return vm
3783
+ }
3784
+ // array of events
3785
+ if (Array.isArray(event)) {
3786
+ for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {
3787
+ vm.$off(event[i$1], fn);
3788
+ }
3789
+ return vm
3790
+ }
3791
+ // specific event
3792
+ var cbs = vm._events[event];
3793
+ if (!cbs) {
3794
+ return vm
3795
+ }
3796
+ if (!fn) {
3797
+ vm._events[event] = null;
3798
+ return vm
3799
+ }
3800
+ // specific handler
3801
+ var cb;
3802
+ var i = cbs.length;
3803
+ while (i--) {
3804
+ cb = cbs[i];
3805
+ if (cb === fn || cb.fn === fn) {
3806
+ cbs.splice(i, 1);
3807
+ break
3808
+ }
3809
+ }
3810
+ return vm
3811
+ };
3777
3812
 
3778
- Vue.prototype.$watch = function (
3779
- expOrFn,
3780
- cb,
3781
- options
3782
- ) {
3813
+ Vue.prototype.$emit = function (event) {
3783
3814
  var vm = this;
3784
- if (isPlainObject(cb)) {
3785
- return createWatcher(vm, expOrFn, cb, options)
3786
- }
3787
- options = options || {};
3788
- options.user = true;
3789
- var watcher = new Watcher(vm, expOrFn, cb, options);
3790
- if (options.immediate) {
3791
- try {
3792
- cb.call(vm, watcher.value);
3793
- } catch (error) {
3794
- handleError(error, vm, ("callback for immediate watcher \"" + (watcher.expression) + "\""));
3815
+ {
3816
+ var lowerCaseEvent = event.toLowerCase();
3817
+ if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
3818
+ tip(
3819
+ "Event \"" + lowerCaseEvent + "\" is emitted in component " +
3820
+ (formatComponentName(vm)) + " but the handler is registered for \"" + event + "\". " +
3821
+ "Note that HTML attributes are case-insensitive and you cannot use " +
3822
+ "v-on to listen to camelCase events when using in-DOM templates. " +
3823
+ "You should probably use \"" + (hyphenate(event)) + "\" instead of \"" + event + "\"."
3824
+ );
3795
3825
  }
3796
3826
  }
3797
- return function unwatchFn () {
3798
- watcher.teardown();
3827
+ var cbs = vm._events[event];
3828
+ if (cbs) {
3829
+ cbs = cbs.length > 1 ? toArray(cbs) : cbs;
3830
+ var args = toArray(arguments, 1);
3831
+ var info = "event handler for \"" + event + "\"";
3832
+ for (var i = 0, l = cbs.length; i < l; i++) {
3833
+ invokeWithErrorHandling(cbs[i], vm, args, vm, info);
3834
+ }
3799
3835
  }
3836
+ return vm
3800
3837
  };
3801
3838
  }
3802
3839
 
3803
3840
  /* */
3804
3841
 
3805
- function initProvide (vm) {
3806
- var provide = vm.$options.provide;
3807
- if (provide) {
3808
- vm._provided = typeof provide === 'function'
3809
- ? provide.call(vm)
3810
- : provide;
3811
- }
3812
- }
3842
+ var activeInstance = null;
3843
+ var isUpdatingChildComponent = false;
3813
3844
 
3814
- function initInjections (vm) {
3815
- var result = resolveInject(vm.$options.inject, vm);
3816
- if (result) {
3817
- toggleObserving(false);
3818
- Object.keys(result).forEach(function (key) {
3819
- /* istanbul ignore else */
3820
- {
3821
- defineReactive$$1(vm, key, result[key], function () {
3822
- warn(
3823
- "Avoid mutating an injected value directly since the changes will be " +
3824
- "overwritten whenever the provided component re-renders. " +
3825
- "injection being mutated: \"" + key + "\"",
3826
- vm
3827
- );
3828
- });
3829
- }
3830
- });
3831
- toggleObserving(true);
3845
+ function setActiveInstance(vm) {
3846
+ var prevActiveInstance = activeInstance;
3847
+ activeInstance = vm;
3848
+ return function () {
3849
+ activeInstance = prevActiveInstance;
3832
3850
  }
3833
3851
  }
3834
3852
 
3835
- function resolveInject (inject, vm) {
3836
- if (inject) {
3837
- // inject is :any because flow is not smart enough to figure out cached
3838
- var result = Object.create(null);
3839
- var keys = hasSymbol
3840
- ? Reflect.ownKeys(inject)
3841
- : Object.keys(inject);
3853
+ function initLifecycle (vm) {
3854
+ var options = vm.$options;
3842
3855
 
3843
- for (var i = 0; i < keys.length; i++) {
3844
- var key = keys[i];
3845
- // #6574 in case the inject object is observed...
3846
- if (key === '__ob__') { continue }
3847
- var provideKey = inject[key].from;
3848
- var source = vm;
3849
- while (source) {
3850
- if (source._provided && hasOwn(source._provided, provideKey)) {
3851
- result[key] = source._provided[provideKey];
3852
- break
3853
- }
3854
- source = source.$parent;
3855
- }
3856
- if (!source) {
3857
- if ('default' in inject[key]) {
3858
- var provideDefault = inject[key].default;
3859
- result[key] = typeof provideDefault === 'function'
3860
- ? provideDefault.call(vm)
3861
- : provideDefault;
3862
- } else {
3863
- warn(("Injection \"" + key + "\" not found"), vm);
3864
- }
3865
- }
3856
+ // locate first non-abstract parent
3857
+ var parent = options.parent;
3858
+ if (parent && !options.abstract) {
3859
+ while (parent.$options.abstract && parent.$parent) {
3860
+ parent = parent.$parent;
3866
3861
  }
3867
- return result
3862
+ parent.$children.push(vm);
3868
3863
  }
3869
- }
3870
-
3871
- /* */
3872
3864
 
3873
- function normalizeScopedSlots (
3874
- slots,
3875
- normalSlots
3876
- ) {
3877
- var res;
3878
- if (!slots) {
3879
- res = {};
3880
- } else if (slots._normalized) {
3881
- return slots
3882
- } else {
3883
- res = {};
3884
- for (var key in slots) {
3885
- if (slots[key] && key[0] !== '$') {
3886
- res[key] = normalizeScopedSlot(normalSlots, key, slots[key]);
3887
- }
3888
- }
3889
- }
3890
- // expose normal slots on scopedSlots
3891
- for (var key$1 in normalSlots) {
3892
- if (!(key$1 in res)) {
3893
- res[key$1] = proxyNormalSlot(normalSlots, key$1);
3894
- }
3895
- }
3896
- res._normalized = true;
3897
- res.$stable = slots ? slots.$stable : true;
3898
- return res
3899
- }
3865
+ vm.$parent = parent;
3866
+ vm.$root = parent ? parent.$root : vm;
3900
3867
 
3901
- function normalizeScopedSlot(normalSlots, key, fn) {
3902
- var normalized = function (scope) {
3903
- if ( scope === void 0 ) scope = {};
3868
+ vm.$children = [];
3869
+ vm.$refs = {};
3904
3870
 
3905
- var res = fn(scope);
3906
- return res && typeof res === 'object' && !Array.isArray(res)
3907
- ? [res] // single vnode
3908
- : normalizeChildren(res)
3909
- };
3910
- // proxy scoped slots on normal $slots
3911
- if (!hasOwn(normalSlots, key)) {
3912
- Object.defineProperty(normalSlots, key, {
3913
- get: normalized
3914
- });
3915
- }
3916
- return normalized
3871
+ vm._watcher = null;
3872
+ vm._inactive = null;
3873
+ vm._directInactive = false;
3874
+ vm._isMounted = false;
3875
+ vm._isDestroyed = false;
3876
+ vm._isBeingDestroyed = false;
3917
3877
  }
3918
3878
 
3919
- function proxyNormalSlot(slots, key) {
3920
- return function () { return slots[key]; }
3921
- }
3879
+ function lifecycleMixin (Vue) {
3880
+ Vue.prototype._update = function (vnode, hydrating) {
3881
+ var vm = this;
3882
+ var prevEl = vm.$el;
3883
+ var prevVnode = vm._vnode;
3884
+ var restoreActiveInstance = setActiveInstance(vm);
3885
+ vm._vnode = vnode;
3886
+ // Vue.prototype.__patch__ is injected in entry points
3887
+ // based on the rendering backend used.
3888
+ if (!prevVnode) {
3889
+ // initial render
3890
+ vm.$el = vm.__patch__(vm.$el, vnode, hydrating, false /* removeOnly */);
3891
+ } else {
3892
+ // updates
3893
+ vm.$el = vm.__patch__(prevVnode, vnode);
3894
+ }
3895
+ restoreActiveInstance();
3896
+ // update __vue__ reference
3897
+ if (prevEl) {
3898
+ prevEl.__vue__ = null;
3899
+ }
3900
+ if (vm.$el) {
3901
+ vm.$el.__vue__ = vm;
3902
+ }
3903
+ // if parent is an HOC, update its $el as well
3904
+ if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) {
3905
+ vm.$parent.$el = vm.$el;
3906
+ }
3907
+ // updated hook is called by the scheduler to ensure that children are
3908
+ // updated in a parent's updated hook.
3909
+ };
3922
3910
 
3923
- /* */
3911
+ Vue.prototype.$forceUpdate = function () {
3912
+ var vm = this;
3913
+ if (vm._watcher) {
3914
+ vm._watcher.update();
3915
+ }
3916
+ };
3924
3917
 
3925
- /**
3926
- * Runtime helper for rendering v-for lists.
3927
- */
3928
- function renderList (
3929
- val,
3930
- render
3931
- ) {
3932
- var ret, i, l, keys, key;
3933
- if (Array.isArray(val) || typeof val === 'string') {
3934
- ret = new Array(val.length);
3935
- for (i = 0, l = val.length; i < l; i++) {
3936
- ret[i] = render(val[i], i);
3918
+ Vue.prototype.$destroy = function () {
3919
+ var vm = this;
3920
+ if (vm._isBeingDestroyed) {
3921
+ return
3937
3922
  }
3938
- } else if (typeof val === 'number') {
3939
- ret = new Array(val);
3940
- for (i = 0; i < val; i++) {
3941
- ret[i] = render(i + 1, i);
3923
+ callHook(vm, 'beforeDestroy');
3924
+ vm._isBeingDestroyed = true;
3925
+ // remove self from parent
3926
+ var parent = vm.$parent;
3927
+ if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
3928
+ remove(parent.$children, vm);
3929
+ }
3930
+ // teardown watchers
3931
+ if (vm._watcher) {
3932
+ vm._watcher.teardown();
3933
+ }
3934
+ var i = vm._watchers.length;
3935
+ while (i--) {
3936
+ vm._watchers[i].teardown();
3937
+ }
3938
+ // remove reference from data ob
3939
+ // frozen object may not have observer.
3940
+ if (vm._data.__ob__) {
3941
+ vm._data.__ob__.vmCount--;
3942
3942
  }
3943
- } else if (isObject(val)) {
3944
- if (hasSymbol && val[Symbol.iterator]) {
3945
- ret = [];
3946
- var iterator = val[Symbol.iterator]();
3947
- var result = iterator.next();
3948
- while (!result.done) {
3949
- ret.push(render(result.value, ret.length));
3950
- result = iterator.next();
3951
- }
3952
- } else {
3953
- keys = Object.keys(val);
3954
- ret = new Array(keys.length);
3955
- for (i = 0, l = keys.length; i < l; i++) {
3956
- key = keys[i];
3957
- ret[i] = render(val[key], key, i);
3958
- }
3943
+ // call the last hook...
3944
+ vm._isDestroyed = true;
3945
+ // invoke destroy hooks on current rendered tree
3946
+ vm.__patch__(vm._vnode, null);
3947
+ // fire destroyed hook
3948
+ callHook(vm, 'destroyed');
3949
+ // turn off all instance listeners.
3950
+ vm.$off();
3951
+ // remove __vue__ reference
3952
+ if (vm.$el) {
3953
+ vm.$el.__vue__ = null;
3959
3954
  }
3960
- }
3961
- if (!isDef(ret)) {
3962
- ret = [];
3963
- }
3964
- (ret)._isVList = true;
3965
- return ret
3955
+ // release circular reference (#6759)
3956
+ if (vm.$vnode) {
3957
+ vm.$vnode.parent = null;
3958
+ }
3959
+ };
3966
3960
  }
3967
3961
 
3968
- /* */
3969
-
3970
- /**
3971
- * Runtime helper for rendering <slot>
3972
- */
3973
- function renderSlot (
3974
- name,
3975
- fallback,
3976
- props,
3977
- bindObject
3962
+ function mountComponent (
3963
+ vm,
3964
+ el,
3965
+ hydrating
3978
3966
  ) {
3979
- var scopedSlotFn = this.$scopedSlots[name];
3980
- var nodes;
3981
- if (scopedSlotFn) { // scoped slot
3982
- props = props || {};
3983
- if (bindObject) {
3984
- if (!isObject(bindObject)) {
3967
+ vm.$el = el;
3968
+ if (!vm.$options.render) {
3969
+ vm.$options.render = createEmptyVNode;
3970
+ {
3971
+ /* istanbul ignore if */
3972
+ if ((vm.$options.template && vm.$options.template.charAt(0) !== '#') ||
3973
+ vm.$options.el || el) {
3985
3974
  warn(
3986
- 'slot v-bind without argument expects an Object',
3987
- this
3975
+ 'You are using the runtime-only build of Vue where the template ' +
3976
+ 'compiler is not available. Either pre-compile the templates into ' +
3977
+ 'render functions, or use the compiler-included build.',
3978
+ vm
3979
+ );
3980
+ } else {
3981
+ warn(
3982
+ 'Failed to mount component: template or render function not defined.',
3983
+ vm
3988
3984
  );
3989
3985
  }
3990
- props = extend(extend({}, bindObject), props);
3991
3986
  }
3992
- nodes = scopedSlotFn(props) || fallback;
3993
- } else {
3994
- nodes = this.$slots[name] || fallback;
3995
3987
  }
3988
+ callHook(vm, 'beforeMount');
3996
3989
 
3997
- var target = props && props.slot;
3998
- if (target) {
3999
- return this.$createElement('template', { slot: target }, nodes)
4000
- } else {
4001
- return nodes
4002
- }
4003
- }
3990
+ var updateComponent;
3991
+ /* istanbul ignore if */
3992
+ if (config.performance && mark) {
3993
+ updateComponent = function () {
3994
+ var name = vm._name;
3995
+ var id = vm._uid;
3996
+ var startTag = "vue-perf-start:" + id;
3997
+ var endTag = "vue-perf-end:" + id;
4004
3998
 
4005
- /* */
3999
+ mark(startTag);
4000
+ var vnode = vm._render();
4001
+ mark(endTag);
4002
+ measure(("vue " + name + " render"), startTag, endTag);
4006
4003
 
4007
- /**
4008
- * Runtime helper for resolving filters
4009
- */
4010
- function resolveFilter (id) {
4011
- return resolveAsset(this.$options, 'filters', id, true) || identity
4012
- }
4004
+ mark(startTag);
4005
+ vm._update(vnode, hydrating);
4006
+ mark(endTag);
4007
+ measure(("vue " + name + " patch"), startTag, endTag);
4008
+ };
4009
+ } else {
4010
+ updateComponent = function () {
4011
+ vm._update(vm._render(), hydrating);
4012
+ };
4013
+ }
4013
4014
 
4014
- /* */
4015
+ // we set this to vm._watcher inside the watcher's constructor
4016
+ // since the watcher's initial patch may call $forceUpdate (e.g. inside child
4017
+ // component's mounted hook), which relies on vm._watcher being already defined
4018
+ new Watcher(vm, updateComponent, noop, {
4019
+ before: function before () {
4020
+ if (vm._isMounted && !vm._isDestroyed) {
4021
+ callHook(vm, 'beforeUpdate');
4022
+ }
4023
+ }
4024
+ }, true /* isRenderWatcher */);
4025
+ hydrating = false;
4015
4026
 
4016
- function isKeyNotMatch (expect, actual) {
4017
- if (Array.isArray(expect)) {
4018
- return expect.indexOf(actual) === -1
4019
- } else {
4020
- return expect !== actual
4027
+ // manually mounted instance, call mounted on self
4028
+ // mounted is called for render-created child components in its inserted hook
4029
+ if (vm.$vnode == null) {
4030
+ vm._isMounted = true;
4031
+ callHook(vm, 'mounted');
4021
4032
  }
4033
+ return vm
4022
4034
  }
4023
4035
 
4024
- /**
4025
- * Runtime helper for checking keyCodes from config.
4026
- * exposed as Vue.prototype._k
4027
- * passing in eventKeyName as last argument separately for backwards compat
4028
- */
4029
- function checkKeyCodes (
4030
- eventKeyCode,
4031
- key,
4032
- builtInKeyCode,
4033
- eventKeyName,
4034
- builtInKeyName
4036
+ function updateChildComponent (
4037
+ vm,
4038
+ propsData,
4039
+ listeners,
4040
+ parentVnode,
4041
+ renderChildren
4035
4042
  ) {
4036
- var mappedKeyCode = config.keyCodes[key] || builtInKeyCode;
4037
- if (builtInKeyName && eventKeyName && !config.keyCodes[key]) {
4038
- return isKeyNotMatch(builtInKeyName, eventKeyName)
4039
- } else if (mappedKeyCode) {
4040
- return isKeyNotMatch(mappedKeyCode, eventKeyCode)
4041
- } else if (eventKeyName) {
4042
- return hyphenate(eventKeyName) !== key
4043
+ {
4044
+ isUpdatingChildComponent = true;
4043
4045
  }
4044
- }
4045
4046
 
4046
- /* */
4047
+ // determine whether component has slot children
4048
+ // we need to do this before overwriting $options._renderChildren.
4047
4049
 
4048
- /**
4049
- * Runtime helper for merging v-bind="object" into a VNode's data.
4050
- */
4051
- function bindObjectProps (
4052
- data,
4053
- tag,
4054
- value,
4055
- asProp,
4056
- isSync
4057
- ) {
4058
- if (value) {
4059
- if (!isObject(value)) {
4060
- warn(
4061
- 'v-bind without argument expects an Object or Array value',
4062
- this
4063
- );
4064
- } else {
4065
- if (Array.isArray(value)) {
4066
- value = toObject(value);
4067
- }
4068
- var hash;
4069
- var loop = function ( key ) {
4070
- if (
4071
- key === 'class' ||
4072
- key === 'style' ||
4073
- isReservedAttribute(key)
4074
- ) {
4075
- hash = data;
4076
- } else {
4077
- var type = data.attrs && data.attrs.type;
4078
- hash = asProp || config.mustUseProp(tag, type, key)
4079
- ? data.domProps || (data.domProps = {})
4080
- : data.attrs || (data.attrs = {});
4081
- }
4082
- var camelizedKey = camelize(key);
4083
- if (!(key in hash) && !(camelizedKey in hash)) {
4084
- hash[key] = value[key];
4050
+ // check if there are dynamic scopedSlots (hand-written or compiled but with
4051
+ // dynamic slot names). Static scoped slots compiled from template has the
4052
+ // "$stable" marker.
4053
+ var hasDynamicScopedSlot = !!(
4054
+ (parentVnode.data.scopedSlots && !parentVnode.data.scopedSlots.$stable) ||
4055
+ (vm.$scopedSlots !== emptyObject && !vm.$scopedSlots.$stable)
4056
+ );
4085
4057
 
4086
- if (isSync) {
4087
- var on = data.on || (data.on = {});
4088
- on[("update:" + camelizedKey)] = function ($event) {
4089
- value[key] = $event;
4090
- };
4091
- }
4092
- }
4093
- };
4058
+ // Any static slot children from the parent may have changed during parent's
4059
+ // update. Dynamic scoped slots may also have changed. In such cases, a forced
4060
+ // update is necessary to ensure correctness.
4061
+ var needsForceUpdate = !!(
4062
+ renderChildren || // has new static slots
4063
+ vm.$options._renderChildren || // has old static slots
4064
+ hasDynamicScopedSlot
4065
+ );
4094
4066
 
4095
- for (var key in value) loop( key );
4067
+ vm.$options._parentVnode = parentVnode;
4068
+ vm.$vnode = parentVnode; // update vm's placeholder node without re-render
4069
+
4070
+ if (vm._vnode) { // update child tree's parent
4071
+ vm._vnode.parent = parentVnode;
4072
+ }
4073
+ vm.$options._renderChildren = renderChildren;
4074
+
4075
+ // update $attrs and $listeners hash
4076
+ // these are also reactive so they may trigger child update if the child
4077
+ // used them during render
4078
+ vm.$attrs = parentVnode.data.attrs || emptyObject;
4079
+ vm.$listeners = listeners || emptyObject;
4080
+
4081
+ // update props
4082
+ if (propsData && vm.$options.props) {
4083
+ toggleObserving(false);
4084
+ var props = vm._props;
4085
+ var propKeys = vm.$options._propKeys || [];
4086
+ for (var i = 0; i < propKeys.length; i++) {
4087
+ var key = propKeys[i];
4088
+ var propOptions = vm.$options.props; // wtf flow?
4089
+ props[key] = validateProp(key, propOptions, propsData, vm);
4096
4090
  }
4091
+ toggleObserving(true);
4092
+ // keep a copy of raw propsData
4093
+ vm.$options.propsData = propsData;
4097
4094
  }
4098
- return data
4099
- }
4100
4095
 
4101
- /* */
4096
+ // update listeners
4097
+ listeners = listeners || emptyObject;
4098
+ var oldListeners = vm.$options._parentListeners;
4099
+ vm.$options._parentListeners = listeners;
4100
+ updateComponentListeners(vm, listeners, oldListeners);
4102
4101
 
4103
- /**
4104
- * Runtime helper for rendering static trees.
4105
- */
4106
- function renderStatic (
4107
- index,
4108
- isInFor
4109
- ) {
4110
- var cached = this._staticTrees || (this._staticTrees = []);
4111
- var tree = cached[index];
4112
- // if has already-rendered static tree and not inside v-for,
4113
- // we can reuse the same tree.
4114
- if (tree && !isInFor) {
4115
- return tree
4102
+ // resolve slots + force update if has children
4103
+ if (needsForceUpdate) {
4104
+ vm.$slots = resolveSlots(renderChildren, parentVnode.context);
4105
+ vm.$forceUpdate();
4116
4106
  }
4117
- // otherwise, render a fresh tree.
4118
- tree = cached[index] = this.$options.staticRenderFns[index].call(
4119
- this._renderProxy,
4120
- null,
4121
- this // for render fns generated for functional component templates
4122
- );
4123
- markStatic(tree, ("__static__" + index), false);
4124
- return tree
4125
- }
4126
-
4127
- /**
4128
- * Runtime helper for v-once.
4129
- * Effectively it means marking the node as static with a unique key.
4130
- */
4131
- function markOnce (
4132
- tree,
4133
- index,
4134
- key
4135
- ) {
4136
- markStatic(tree, ("__once__" + index + (key ? ("_" + key) : "")), true);
4137
- return tree
4138
- }
4139
4107
 
4140
- function markStatic (
4141
- tree,
4142
- key,
4143
- isOnce
4144
- ) {
4145
- if (Array.isArray(tree)) {
4146
- for (var i = 0; i < tree.length; i++) {
4147
- if (tree[i] && typeof tree[i] !== 'string') {
4148
- markStaticNode(tree[i], (key + "_" + i), isOnce);
4149
- }
4150
- }
4151
- } else {
4152
- markStaticNode(tree, key, isOnce);
4108
+ {
4109
+ isUpdatingChildComponent = false;
4153
4110
  }
4154
4111
  }
4155
4112
 
4156
- function markStaticNode (node, key, isOnce) {
4157
- node.isStatic = true;
4158
- node.key = key;
4159
- node.isOnce = isOnce;
4113
+ function isInInactiveTree (vm) {
4114
+ while (vm && (vm = vm.$parent)) {
4115
+ if (vm._inactive) { return true }
4116
+ }
4117
+ return false
4160
4118
  }
4161
4119
 
4162
- /* */
4163
-
4164
- function bindObjectListeners (data, value) {
4165
- if (value) {
4166
- if (!isPlainObject(value)) {
4167
- warn(
4168
- 'v-on without argument expects an Object value',
4169
- this
4170
- );
4171
- } else {
4172
- var on = data.on = data.on ? extend({}, data.on) : {};
4173
- for (var key in value) {
4174
- var existing = on[key];
4175
- var ours = value[key];
4176
- on[key] = existing ? [].concat(existing, ours) : ours;
4177
- }
4120
+ function activateChildComponent (vm, direct) {
4121
+ if (direct) {
4122
+ vm._directInactive = false;
4123
+ if (isInInactiveTree(vm)) {
4124
+ return
4178
4125
  }
4126
+ } else if (vm._directInactive) {
4127
+ return
4128
+ }
4129
+ if (vm._inactive || vm._inactive === null) {
4130
+ vm._inactive = false;
4131
+ for (var i = 0; i < vm.$children.length; i++) {
4132
+ activateChildComponent(vm.$children[i]);
4133
+ }
4134
+ callHook(vm, 'activated');
4179
4135
  }
4180
- return data
4181
4136
  }
4182
4137
 
4183
- /* */
4184
-
4185
- function bindDynamicKeys (baseObj, values) {
4186
- for (var i = 0; i < values.length; i += 2) {
4187
- var key = values[i];
4188
- if (typeof key === 'string' && key) {
4189
- baseObj[values[i]] = values[i + 1];
4190
- } else if (key !== '' && key !== null) {
4191
- // null is a speical value for explicitly removing a binding
4192
- warn(
4193
- ("Invalid value for dynamic directive argument (expected string or null): " + key),
4194
- this
4195
- );
4138
+ function deactivateChildComponent (vm, direct) {
4139
+ if (direct) {
4140
+ vm._directInactive = true;
4141
+ if (isInInactiveTree(vm)) {
4142
+ return
4196
4143
  }
4197
4144
  }
4198
- return baseObj
4145
+ if (!vm._inactive) {
4146
+ vm._inactive = true;
4147
+ for (var i = 0; i < vm.$children.length; i++) {
4148
+ deactivateChildComponent(vm.$children[i]);
4149
+ }
4150
+ callHook(vm, 'deactivated');
4151
+ }
4199
4152
  }
4200
4153
 
4201
- // helper to dynamically append modifier runtime markers to event names.
4202
- // ensure only append when value is already string, otherwise it will be cast
4203
- // to string and cause the type check to miss.
4204
- function prependModifier (value, symbol) {
4205
- return typeof value === 'string' ? symbol + value : value
4154
+ function callHook (vm, hook) {
4155
+ // #7573 disable dep collection when invoking lifecycle hooks
4156
+ pushTarget();
4157
+ var handlers = vm.$options[hook];
4158
+ var info = hook + " hook";
4159
+ if (handlers) {
4160
+ for (var i = 0, j = handlers.length; i < j; i++) {
4161
+ invokeWithErrorHandling(handlers[i], vm, null, vm, info);
4162
+ }
4163
+ }
4164
+ if (vm._hasHookEvent) {
4165
+ vm.$emit('hook:' + hook);
4166
+ }
4167
+ popTarget();
4206
4168
  }
4207
4169
 
4208
4170
  /* */
4209
4171
 
4210
- function installRenderHelpers (target) {
4211
- target._o = markOnce;
4212
- target._n = toNumber;
4213
- target._s = toString;
4214
- target._l = renderList;
4215
- target._t = renderSlot;
4216
- target._q = looseEqual;
4217
- target._i = looseIndexOf;
4218
- target._m = renderStatic;
4219
- target._f = resolveFilter;
4220
- target._k = checkKeyCodes;
4221
- target._b = bindObjectProps;
4222
- target._v = createTextVNode;
4223
- target._e = createEmptyVNode;
4224
- target._u = resolveScopedSlots;
4225
- target._g = bindObjectListeners;
4226
- target._d = bindDynamicKeys;
4227
- target._p = prependModifier;
4228
- }
4172
+ var MAX_UPDATE_COUNT = 100;
4229
4173
 
4230
- /* */
4174
+ var queue = [];
4175
+ var activatedChildren = [];
4176
+ var has = {};
4177
+ var circular = {};
4178
+ var waiting = false;
4179
+ var flushing = false;
4180
+ var index = 0;
4231
4181
 
4232
- function FunctionalRenderContext (
4233
- data,
4234
- props,
4235
- children,
4236
- parent,
4237
- Ctor
4238
- ) {
4239
- var options = Ctor.options;
4240
- // ensure the createElement function in functional components
4241
- // gets a unique context - this is necessary for correct named slot check
4242
- var contextVm;
4243
- if (hasOwn(parent, '_uid')) {
4244
- contextVm = Object.create(parent);
4245
- // $flow-disable-line
4246
- contextVm._original = parent;
4247
- } else {
4248
- // the context vm passed in is a functional context as well.
4249
- // in this case we want to make sure we are able to get a hold to the
4250
- // real context instance.
4251
- contextVm = parent;
4252
- // $flow-disable-line
4253
- parent = parent._original;
4182
+ /**
4183
+ * Reset the scheduler's state.
4184
+ */
4185
+ function resetSchedulerState () {
4186
+ index = queue.length = activatedChildren.length = 0;
4187
+ has = {};
4188
+ {
4189
+ circular = {};
4254
4190
  }
4255
- var isCompiled = isTrue(options._compiled);
4256
- var needNormalization = !isCompiled;
4257
-
4258
- this.data = data;
4259
- this.props = props;
4260
- this.children = children;
4261
- this.parent = parent;
4262
- this.listeners = data.on || emptyObject;
4263
- this.injections = resolveInject(options.inject, parent);
4264
- this.slots = function () { return resolveSlots(children, parent); };
4191
+ waiting = flushing = false;
4192
+ }
4265
4193
 
4266
- Object.defineProperty(this, 'scopedSlots', ({
4267
- enumerable: true,
4268
- get: function get () {
4269
- return normalizeScopedSlots(data.scopedSlots, this.slots())
4270
- }
4271
- }));
4194
+ // Async edge case #6566 requires saving the timestamp when event listeners are
4195
+ // attached. However, calling performance.now() has a perf overhead especially
4196
+ // if the page has thousands of event listeners. Instead, we take a timestamp
4197
+ // every time the scheduler flushes and use that for all event listeners
4198
+ // attached during that flush.
4199
+ var currentFlushTimestamp = 0;
4272
4200
 
4273
- // support for compiled functional template
4274
- if (isCompiled) {
4275
- // exposing $options for renderStatic()
4276
- this.$options = options;
4277
- // pre-resolve slots for renderSlot()
4278
- this.$slots = this.slots();
4279
- this.$scopedSlots = normalizeScopedSlots(data.scopedSlots, this.$slots);
4280
- }
4201
+ // Async edge case fix requires storing an event listener's attach timestamp.
4202
+ var getNow = Date.now;
4281
4203
 
4282
- if (options._scopeId) {
4283
- this._c = function (a, b, c, d) {
4284
- var vnode = createElement(contextVm, a, b, c, d, needNormalization);
4285
- if (vnode && !Array.isArray(vnode)) {
4286
- vnode.fnScopeId = options._scopeId;
4287
- vnode.fnContext = parent;
4288
- }
4289
- return vnode
4290
- };
4291
- } else {
4292
- this._c = function (a, b, c, d) { return createElement(contextVm, a, b, c, d, needNormalization); };
4293
- }
4204
+ // Determine what event timestamp the browser is using. Annoyingly, the
4205
+ // timestamp can either be hi-res (relative to page load) or low-res
4206
+ // (relative to UNIX epoch), so in order to compare time we have to use the
4207
+ // same timestamp type when saving the flush timestamp.
4208
+ if (inBrowser && getNow() > document.createEvent('Event').timeStamp) {
4209
+ // if the low-res timestamp which is bigger than the event timestamp
4210
+ // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
4211
+ // and we need to use the hi-res version for event listeners as well.
4212
+ getNow = function () { return performance.now(); };
4294
4213
  }
4295
4214
 
4296
- installRenderHelpers(FunctionalRenderContext.prototype);
4215
+ /**
4216
+ * Flush both queues and run the watchers.
4217
+ */
4218
+ function flushSchedulerQueue () {
4219
+ currentFlushTimestamp = getNow();
4220
+ flushing = true;
4221
+ var watcher, id;
4297
4222
 
4298
- function createFunctionalComponent (
4299
- Ctor,
4300
- propsData,
4301
- data,
4302
- contextVm,
4303
- children
4304
- ) {
4305
- var options = Ctor.options;
4306
- var props = {};
4307
- var propOptions = options.props;
4308
- if (isDef(propOptions)) {
4309
- for (var key in propOptions) {
4310
- props[key] = validateProp(key, propOptions, propsData || emptyObject);
4223
+ // Sort queue before flush.
4224
+ // This ensures that:
4225
+ // 1. Components are updated from parent to child. (because parent is always
4226
+ // created before the child)
4227
+ // 2. A component's user watchers are run before its render watcher (because
4228
+ // user watchers are created before the render watcher)
4229
+ // 3. If a component is destroyed during a parent component's watcher run,
4230
+ // its watchers can be skipped.
4231
+ queue.sort(function (a, b) { return a.id - b.id; });
4232
+
4233
+ // do not cache length because more watchers might be pushed
4234
+ // as we run existing watchers
4235
+ for (index = 0; index < queue.length; index++) {
4236
+ watcher = queue[index];
4237
+ if (watcher.before) {
4238
+ watcher.before();
4239
+ }
4240
+ id = watcher.id;
4241
+ has[id] = null;
4242
+ watcher.run();
4243
+ // in dev build, check and stop circular updates.
4244
+ if (has[id] != null) {
4245
+ circular[id] = (circular[id] || 0) + 1;
4246
+ if (circular[id] > MAX_UPDATE_COUNT) {
4247
+ warn(
4248
+ 'You may have an infinite update loop ' + (
4249
+ watcher.user
4250
+ ? ("in watcher with expression \"" + (watcher.expression) + "\"")
4251
+ : "in a component render function."
4252
+ ),
4253
+ watcher.vm
4254
+ );
4255
+ break
4256
+ }
4311
4257
  }
4312
- } else {
4313
- if (isDef(data.attrs)) { mergeProps(props, data.attrs); }
4314
- if (isDef(data.props)) { mergeProps(props, data.props); }
4315
4258
  }
4316
4259
 
4317
- var renderContext = new FunctionalRenderContext(
4318
- data,
4319
- props,
4320
- children,
4321
- contextVm,
4322
- Ctor
4323
- );
4260
+ // keep copies of post queues before resetting state
4261
+ var activatedQueue = activatedChildren.slice();
4262
+ var updatedQueue = queue.slice();
4324
4263
 
4325
- var vnode = options.render.call(null, renderContext._c, renderContext);
4264
+ resetSchedulerState();
4326
4265
 
4327
- if (vnode instanceof VNode) {
4328
- return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext)
4329
- } else if (Array.isArray(vnode)) {
4330
- var vnodes = normalizeChildren(vnode) || [];
4331
- var res = new Array(vnodes.length);
4332
- for (var i = 0; i < vnodes.length; i++) {
4333
- res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
4334
- }
4335
- return res
4266
+ // call component updated and activated hooks
4267
+ callActivatedHooks(activatedQueue);
4268
+ callUpdatedHooks(updatedQueue);
4269
+
4270
+ // devtool hook
4271
+ /* istanbul ignore if */
4272
+ if (devtools && config.devtools) {
4273
+ devtools.emit('flush');
4336
4274
  }
4337
4275
  }
4338
4276
 
4339
- function cloneAndMarkFunctionalResult (vnode, data, contextVm, options, renderContext) {
4340
- // #7817 clone node before setting fnContext, otherwise if the node is reused
4341
- // (e.g. it was from a cached normal slot) the fnContext causes named slots
4342
- // that should not be matched to match.
4343
- var clone = cloneVNode(vnode);
4344
- clone.fnContext = contextVm;
4345
- clone.fnOptions = options;
4346
- {
4347
- (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext = renderContext;
4348
- }
4349
- if (data.slot) {
4350
- (clone.data || (clone.data = {})).slot = data.slot;
4277
+ function callUpdatedHooks (queue) {
4278
+ var i = queue.length;
4279
+ while (i--) {
4280
+ var watcher = queue[i];
4281
+ var vm = watcher.vm;
4282
+ if (vm._watcher === watcher && vm._isMounted && !vm._isDestroyed) {
4283
+ callHook(vm, 'updated');
4284
+ }
4351
4285
  }
4352
- return clone
4353
4286
  }
4354
4287
 
4355
- function mergeProps (to, from) {
4356
- for (var key in from) {
4357
- to[camelize(key)] = from[key];
4358
- }
4288
+ /**
4289
+ * Queue a kept-alive component that was activated during patch.
4290
+ * The queue will be processed after the entire tree has been patched.
4291
+ */
4292
+ function queueActivatedComponent (vm) {
4293
+ // setting _inactive to false here so that a render function can
4294
+ // rely on checking whether it's in an inactive tree (e.g. router-view)
4295
+ vm._inactive = false;
4296
+ activatedChildren.push(vm);
4359
4297
  }
4360
4298
 
4361
- /* */
4299
+ function callActivatedHooks (queue) {
4300
+ for (var i = 0; i < queue.length; i++) {
4301
+ queue[i]._inactive = true;
4302
+ activateChildComponent(queue[i], true /* true */);
4303
+ }
4304
+ }
4362
4305
 
4363
- /* */
4306
+ /**
4307
+ * Push a watcher into the watcher queue.
4308
+ * Jobs with duplicate IDs will be skipped unless it's
4309
+ * pushed when the queue is being flushed.
4310
+ */
4311
+ function queueWatcher (watcher) {
4312
+ var id = watcher.id;
4313
+ if (has[id] == null) {
4314
+ has[id] = true;
4315
+ if (!flushing) {
4316
+ queue.push(watcher);
4317
+ } else {
4318
+ // if already flushing, splice the watcher based on its id
4319
+ // if already past its id, it will be run next immediately.
4320
+ var i = queue.length - 1;
4321
+ while (i > index && queue[i].id > watcher.id) {
4322
+ i--;
4323
+ }
4324
+ queue.splice(i + 1, 0, watcher);
4325
+ }
4326
+ // queue the flush
4327
+ if (!waiting) {
4328
+ waiting = true;
4364
4329
 
4365
- /* */
4330
+ if (!config.async) {
4331
+ flushSchedulerQueue();
4332
+ return
4333
+ }
4334
+ nextTick(flushSchedulerQueue);
4335
+ }
4336
+ }
4337
+ }
4366
4338
 
4367
4339
  /* */
4368
4340
 
4369
- // inline hooks to be invoked on component VNodes during patch
4370
- var componentVNodeHooks = {
4371
- init: function init (vnode, hydrating) {
4372
- if (
4373
- vnode.componentInstance &&
4374
- !vnode.componentInstance._isDestroyed &&
4375
- vnode.data.keepAlive
4376
- ) {
4377
- // kept-alive components, treat as a patch
4378
- var mountedNode = vnode; // work around flow
4379
- componentVNodeHooks.prepatch(mountedNode, mountedNode);
4380
- } else {
4381
- var child = vnode.componentInstance = createComponentInstanceForVnode(
4382
- vnode,
4383
- activeInstance
4384
- );
4385
- child.$mount(hydrating ? vnode.elm : undefined, hydrating);
4386
- }
4387
- },
4388
4341
 
4389
- prepatch: function prepatch (oldVnode, vnode) {
4390
- var options = vnode.componentOptions;
4391
- var child = vnode.componentInstance = oldVnode.componentInstance;
4392
- updateChildComponent(
4393
- child,
4394
- options.propsData, // updated props
4395
- options.listeners, // updated listeners
4396
- vnode, // new parent vnode
4397
- options.children // new children
4398
- );
4399
- },
4400
4342
 
4401
- insert: function insert (vnode) {
4402
- var context = vnode.context;
4403
- var componentInstance = vnode.componentInstance;
4404
- if (!componentInstance._isMounted) {
4405
- componentInstance._isMounted = true;
4406
- callHook(componentInstance, 'mounted');
4407
- }
4408
- if (vnode.data.keepAlive) {
4409
- if (context._isMounted) {
4410
- // vue-router#1212
4411
- // During updates, a kept-alive component's child components may
4412
- // change, so directly walking the tree here may call activated hooks
4413
- // on incorrect children. Instead we push them into a queue which will
4414
- // be processed after the whole patch process ended.
4415
- queueActivatedComponent(componentInstance);
4416
- } else {
4417
- activateChildComponent(componentInstance, true /* direct */);
4418
- }
4419
- }
4420
- },
4343
+ var uid$2 = 0;
4421
4344
 
4422
- destroy: function destroy (vnode) {
4423
- var componentInstance = vnode.componentInstance;
4424
- if (!componentInstance._isDestroyed) {
4425
- if (!vnode.data.keepAlive) {
4426
- componentInstance.$destroy();
4427
- } else {
4428
- deactivateChildComponent(componentInstance, true /* direct */);
4429
- }
4345
+ /**
4346
+ * A watcher parses an expression, collects dependencies,
4347
+ * and fires callback when the expression value changes.
4348
+ * This is used for both the $watch() api and directives.
4349
+ */
4350
+ var Watcher = function Watcher (
4351
+ vm,
4352
+ expOrFn,
4353
+ cb,
4354
+ options,
4355
+ isRenderWatcher
4356
+ ) {
4357
+ this.vm = vm;
4358
+ if (isRenderWatcher) {
4359
+ vm._watcher = this;
4360
+ }
4361
+ vm._watchers.push(this);
4362
+ // options
4363
+ if (options) {
4364
+ this.deep = !!options.deep;
4365
+ this.user = !!options.user;
4366
+ this.lazy = !!options.lazy;
4367
+ this.sync = !!options.sync;
4368
+ this.before = options.before;
4369
+ } else {
4370
+ this.deep = this.user = this.lazy = this.sync = false;
4371
+ }
4372
+ this.cb = cb;
4373
+ this.id = ++uid$2; // uid for batching
4374
+ this.active = true;
4375
+ this.dirty = this.lazy; // for lazy watchers
4376
+ this.deps = [];
4377
+ this.newDeps = [];
4378
+ this.depIds = new _Set();
4379
+ this.newDepIds = new _Set();
4380
+ this.expression = expOrFn.toString();
4381
+ // parse expression for getter
4382
+ if (typeof expOrFn === 'function') {
4383
+ this.getter = expOrFn;
4384
+ } else {
4385
+ this.getter = parsePath(expOrFn);
4386
+ if (!this.getter) {
4387
+ this.getter = noop;
4388
+ warn(
4389
+ "Failed watching path: \"" + expOrFn + "\" " +
4390
+ 'Watcher only accepts simple dot-delimited paths. ' +
4391
+ 'For full control, use a function instead.',
4392
+ vm
4393
+ );
4430
4394
  }
4431
4395
  }
4396
+ this.value = this.lazy
4397
+ ? undefined
4398
+ : this.get();
4432
4399
  };
4433
4400
 
4434
- var hooksToMerge = Object.keys(componentVNodeHooks);
4435
-
4436
- function createComponent (
4437
- Ctor,
4438
- data,
4439
- context,
4440
- children,
4441
- tag
4442
- ) {
4443
- if (isUndef(Ctor)) {
4444
- return
4445
- }
4446
-
4447
- var baseCtor = context.$options._base;
4448
-
4449
- // plain options object: turn it into a constructor
4450
- if (isObject(Ctor)) {
4451
- Ctor = baseCtor.extend(Ctor);
4452
- }
4453
-
4454
- // if at this stage it's not a constructor or an async component factory,
4455
- // reject.
4456
- if (typeof Ctor !== 'function') {
4457
- {
4458
- warn(("Invalid Component definition: " + (String(Ctor))), context);
4401
+ /**
4402
+ * Evaluate the getter, and re-collect dependencies.
4403
+ */
4404
+ Watcher.prototype.get = function get () {
4405
+ pushTarget(this);
4406
+ var value;
4407
+ var vm = this.vm;
4408
+ try {
4409
+ value = this.getter.call(vm, vm);
4410
+ } catch (e) {
4411
+ if (this.user) {
4412
+ handleError(e, vm, ("getter for watcher \"" + (this.expression) + "\""));
4413
+ } else {
4414
+ throw e
4459
4415
  }
4460
- return
4416
+ } finally {
4417
+ // "touch" every property so they are all tracked as
4418
+ // dependencies for deep watching
4419
+ if (this.deep) {
4420
+ traverse(value);
4421
+ }
4422
+ popTarget();
4423
+ this.cleanupDeps();
4461
4424
  }
4425
+ return value
4426
+ };
4462
4427
 
4463
- // async component
4464
- var asyncFactory;
4465
- if (isUndef(Ctor.cid)) {
4466
- asyncFactory = Ctor;
4467
- Ctor = resolveAsyncComponent(asyncFactory, baseCtor, context);
4468
- if (Ctor === undefined) {
4469
- // return a placeholder node for async component, which is rendered
4470
- // as a comment node but preserves all the raw information for the node.
4471
- // the information will be used for async server-rendering and hydration.
4472
- return createAsyncPlaceholder(
4473
- asyncFactory,
4474
- data,
4475
- context,
4476
- children,
4477
- tag
4478
- )
4428
+ /**
4429
+ * Add a dependency to this directive.
4430
+ */
4431
+ Watcher.prototype.addDep = function addDep (dep) {
4432
+ var id = dep.id;
4433
+ if (!this.newDepIds.has(id)) {
4434
+ this.newDepIds.add(id);
4435
+ this.newDeps.push(dep);
4436
+ if (!this.depIds.has(id)) {
4437
+ dep.addSub(this);
4479
4438
  }
4480
4439
  }
4440
+ };
4481
4441
 
4482
- data = data || {};
4483
-
4484
- // resolve constructor options in case global mixins are applied after
4485
- // component constructor creation
4486
- resolveConstructorOptions(Ctor);
4487
-
4488
- // transform component v-model data into props & events
4489
- if (isDef(data.model)) {
4490
- transformModel(Ctor.options, data);
4442
+ /**
4443
+ * Clean up for dependency collection.
4444
+ */
4445
+ Watcher.prototype.cleanupDeps = function cleanupDeps () {
4446
+ var i = this.deps.length;
4447
+ while (i--) {
4448
+ var dep = this.deps[i];
4449
+ if (!this.newDepIds.has(dep.id)) {
4450
+ dep.removeSub(this);
4451
+ }
4491
4452
  }
4453
+ var tmp = this.depIds;
4454
+ this.depIds = this.newDepIds;
4455
+ this.newDepIds = tmp;
4456
+ this.newDepIds.clear();
4457
+ tmp = this.deps;
4458
+ this.deps = this.newDeps;
4459
+ this.newDeps = tmp;
4460
+ this.newDeps.length = 0;
4461
+ };
4492
4462
 
4493
- // extract props
4494
- var propsData = extractPropsFromVNodeData(data, Ctor, tag);
4495
-
4496
- // functional component
4497
- if (isTrue(Ctor.options.functional)) {
4498
- return createFunctionalComponent(Ctor, propsData, data, context, children)
4463
+ /**
4464
+ * Subscriber interface.
4465
+ * Will be called when a dependency changes.
4466
+ */
4467
+ Watcher.prototype.update = function update () {
4468
+ /* istanbul ignore else */
4469
+ if (this.lazy) {
4470
+ this.dirty = true;
4471
+ } else if (this.sync) {
4472
+ this.run();
4473
+ } else {
4474
+ queueWatcher(this);
4499
4475
  }
4476
+ };
4500
4477
 
4501
- // extract listeners, since these needs to be treated as
4502
- // child component listeners instead of DOM listeners
4503
- var listeners = data.on;
4504
- // replace with listeners with .native modifier
4505
- // so it gets processed during parent component patch.
4506
- data.on = data.nativeOn;
4507
-
4508
- if (isTrue(Ctor.options.abstract)) {
4509
- // abstract components do not keep anything
4510
- // other than props & listeners & slot
4511
-
4512
- // work around flow
4513
- var slot = data.slot;
4514
- data = {};
4515
- if (slot) {
4516
- data.slot = slot;
4478
+ /**
4479
+ * Scheduler job interface.
4480
+ * Will be called by the scheduler.
4481
+ */
4482
+ Watcher.prototype.run = function run () {
4483
+ if (this.active) {
4484
+ var value = this.get();
4485
+ if (
4486
+ value !== this.value ||
4487
+ // Deep watchers and watchers on Object/Arrays should fire even
4488
+ // when the value is the same, because the value may
4489
+ // have mutated.
4490
+ isObject(value) ||
4491
+ this.deep
4492
+ ) {
4493
+ // set new value
4494
+ var oldValue = this.value;
4495
+ this.value = value;
4496
+ if (this.user) {
4497
+ try {
4498
+ this.cb.call(this.vm, value, oldValue);
4499
+ } catch (e) {
4500
+ handleError(e, this.vm, ("callback for watcher \"" + (this.expression) + "\""));
4501
+ }
4502
+ } else {
4503
+ this.cb.call(this.vm, value, oldValue);
4504
+ }
4517
4505
  }
4518
4506
  }
4507
+ };
4519
4508
 
4520
- // install component management hooks onto the placeholder node
4521
- installComponentHooks(data);
4522
-
4523
- // return a placeholder vnode
4524
- var name = Ctor.options.name || tag;
4525
- var vnode = new VNode(
4526
- ("vue-component-" + (Ctor.cid) + (name ? ("-" + name) : '')),
4527
- data, undefined, undefined, undefined, context,
4528
- { Ctor: Ctor, propsData: propsData, listeners: listeners, tag: tag, children: children },
4529
- asyncFactory
4530
- );
4531
-
4532
- return vnode
4533
- }
4509
+ /**
4510
+ * Evaluate the value of the watcher.
4511
+ * This only gets called for lazy watchers.
4512
+ */
4513
+ Watcher.prototype.evaluate = function evaluate () {
4514
+ this.value = this.get();
4515
+ this.dirty = false;
4516
+ };
4534
4517
 
4535
- function createComponentInstanceForVnode (
4536
- vnode, // we know it's MountedComponentVNode but flow doesn't
4537
- parent // activeInstance in lifecycle state
4538
- ) {
4539
- var options = {
4540
- _isComponent: true,
4541
- _parentVnode: vnode,
4542
- parent: parent
4543
- };
4544
- // check inline-template render functions
4545
- var inlineTemplate = vnode.data.inlineTemplate;
4546
- if (isDef(inlineTemplate)) {
4547
- options.render = inlineTemplate.render;
4548
- options.staticRenderFns = inlineTemplate.staticRenderFns;
4518
+ /**
4519
+ * Depend on all deps collected by this watcher.
4520
+ */
4521
+ Watcher.prototype.depend = function depend () {
4522
+ var i = this.deps.length;
4523
+ while (i--) {
4524
+ this.deps[i].depend();
4549
4525
  }
4550
- return new vnode.componentOptions.Ctor(options)
4551
- }
4526
+ };
4552
4527
 
4553
- function installComponentHooks (data) {
4554
- var hooks = data.hook || (data.hook = {});
4555
- for (var i = 0; i < hooksToMerge.length; i++) {
4556
- var key = hooksToMerge[i];
4557
- var existing = hooks[key];
4558
- var toMerge = componentVNodeHooks[key];
4559
- if (existing !== toMerge && !(existing && existing._merged)) {
4560
- hooks[key] = existing ? mergeHook$1(toMerge, existing) : toMerge;
4528
+ /**
4529
+ * Remove self from all dependencies' subscriber list.
4530
+ */
4531
+ Watcher.prototype.teardown = function teardown () {
4532
+ if (this.active) {
4533
+ // remove self from vm's watcher list
4534
+ // this is a somewhat expensive operation so we skip it
4535
+ // if the vm is being destroyed.
4536
+ if (!this.vm._isBeingDestroyed) {
4537
+ remove(this.vm._watchers, this);
4561
4538
  }
4539
+ var i = this.deps.length;
4540
+ while (i--) {
4541
+ this.deps[i].removeSub(this);
4542
+ }
4543
+ this.active = false;
4562
4544
  }
4563
- }
4545
+ };
4546
+
4547
+ /* */
4564
4548
 
4565
- function mergeHook$1 (f1, f2) {
4566
- var merged = function (a, b) {
4567
- // flow complains about extra args which is why we use any
4568
- f1(a, b);
4569
- f2(a, b);
4549
+ var sharedPropertyDefinition = {
4550
+ enumerable: true,
4551
+ configurable: true,
4552
+ get: noop,
4553
+ set: noop
4554
+ };
4555
+
4556
+ function proxy (target, sourceKey, key) {
4557
+ sharedPropertyDefinition.get = function proxyGetter () {
4558
+ return this[sourceKey][key]
4570
4559
  };
4571
- merged._merged = true;
4572
- return merged
4560
+ sharedPropertyDefinition.set = function proxySetter (val) {
4561
+ this[sourceKey][key] = val;
4562
+ };
4563
+ Object.defineProperty(target, key, sharedPropertyDefinition);
4573
4564
  }
4574
4565
 
4575
- // transform component v-model info (value and callback) into
4576
- // prop and event handler respectively.
4577
- function transformModel (options, data) {
4578
- var prop = (options.model && options.model.prop) || 'value';
4579
- var event = (options.model && options.model.event) || 'input'
4580
- ;(data.attrs || (data.attrs = {}))[prop] = data.model.value;
4581
- var on = data.on || (data.on = {});
4582
- var existing = on[event];
4583
- var callback = data.model.callback;
4584
- if (isDef(existing)) {
4585
- if (
4586
- Array.isArray(existing)
4587
- ? existing.indexOf(callback) === -1
4588
- : existing !== callback
4589
- ) {
4590
- on[event] = [callback].concat(existing);
4591
- }
4566
+ function initState (vm) {
4567
+ vm._watchers = [];
4568
+ var opts = vm.$options;
4569
+ if (opts.props) { initProps(vm, opts.props); }
4570
+ if (opts.methods) { initMethods(vm, opts.methods); }
4571
+ if (opts.data) {
4572
+ initData(vm);
4592
4573
  } else {
4593
- on[event] = callback;
4574
+ observe(vm._data = {}, true /* asRootData */);
4575
+ }
4576
+ if (opts.computed) { initComputed(vm, opts.computed); }
4577
+ if (opts.watch && opts.watch !== nativeWatch) {
4578
+ initWatch(vm, opts.watch);
4594
4579
  }
4595
4580
  }
4596
4581
 
4597
- /* */
4598
-
4599
- var SIMPLE_NORMALIZE = 1;
4600
- var ALWAYS_NORMALIZE = 2;
4601
-
4602
- // wrapper function for providing a more flexible interface
4603
- // without getting yelled at by flow
4604
- function createElement (
4605
- context,
4606
- tag,
4607
- data,
4608
- children,
4609
- normalizationType,
4610
- alwaysNormalize
4611
- ) {
4612
- if (Array.isArray(data) || isPrimitive(data)) {
4613
- normalizationType = children;
4614
- children = data;
4615
- data = undefined;
4616
- }
4617
- if (isTrue(alwaysNormalize)) {
4618
- normalizationType = ALWAYS_NORMALIZE;
4582
+ function initProps (vm, propsOptions) {
4583
+ var propsData = vm.$options.propsData || {};
4584
+ var props = vm._props = {};
4585
+ // cache prop keys so that future props updates can iterate using Array
4586
+ // instead of dynamic object key enumeration.
4587
+ var keys = vm.$options._propKeys = [];
4588
+ var isRoot = !vm.$parent;
4589
+ // root instance props should be converted
4590
+ if (!isRoot) {
4591
+ toggleObserving(false);
4619
4592
  }
4620
- return _createElement(context, tag, data, children, normalizationType)
4593
+ var loop = function ( key ) {
4594
+ keys.push(key);
4595
+ var value = validateProp(key, propsOptions, propsData, vm);
4596
+ /* istanbul ignore else */
4597
+ {
4598
+ var hyphenatedKey = hyphenate(key);
4599
+ if (isReservedAttribute(hyphenatedKey) ||
4600
+ config.isReservedAttr(hyphenatedKey)) {
4601
+ warn(
4602
+ ("\"" + hyphenatedKey + "\" is a reserved attribute and cannot be used as component prop."),
4603
+ vm
4604
+ );
4605
+ }
4606
+ defineReactive$$1(props, key, value, function () {
4607
+ if (!isRoot && !isUpdatingChildComponent) {
4608
+ warn(
4609
+ "Avoid mutating a prop directly since the value will be " +
4610
+ "overwritten whenever the parent component re-renders. " +
4611
+ "Instead, use a data or computed property based on the prop's " +
4612
+ "value. Prop being mutated: \"" + key + "\"",
4613
+ vm
4614
+ );
4615
+ }
4616
+ });
4617
+ }
4618
+ // static props are already proxied on the component's prototype
4619
+ // during Vue.extend(). We only need to proxy props defined at
4620
+ // instantiation here.
4621
+ if (!(key in vm)) {
4622
+ proxy(vm, "_props", key);
4623
+ }
4624
+ };
4625
+
4626
+ for (var key in propsOptions) loop( key );
4627
+ toggleObserving(true);
4621
4628
  }
4622
4629
 
4623
- function _createElement (
4624
- context,
4625
- tag,
4626
- data,
4627
- children,
4628
- normalizationType
4629
- ) {
4630
- if (isDef(data) && isDef((data).__ob__)) {
4630
+ function initData (vm) {
4631
+ var data = vm.$options.data;
4632
+ data = vm._data = typeof data === 'function'
4633
+ ? getData(data, vm)
4634
+ : data || {};
4635
+ if (!isPlainObject(data)) {
4636
+ data = {};
4631
4637
  warn(
4632
- "Avoid using observed data object as vnode data: " + (JSON.stringify(data)) + "\n" +
4633
- 'Always create fresh vnode data objects in each render!',
4634
- context
4638
+ 'data functions should return an object:\n' +
4639
+ 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
4640
+ vm
4635
4641
  );
4636
- return createEmptyVNode()
4637
- }
4638
- // object syntax in v-bind
4639
- if (isDef(data) && isDef(data.is)) {
4640
- tag = data.is;
4641
- }
4642
- if (!tag) {
4643
- // in case of component :is set to falsy value
4644
- return createEmptyVNode()
4645
4642
  }
4646
- // warn against non-primitive key
4647
- if (isDef(data) && isDef(data.key) && !isPrimitive(data.key)
4648
- ) {
4643
+ // proxy data on instance
4644
+ var keys = Object.keys(data);
4645
+ var props = vm.$options.props;
4646
+ var methods = vm.$options.methods;
4647
+ var i = keys.length;
4648
+ while (i--) {
4649
+ var key = keys[i];
4649
4650
  {
4651
+ if (methods && hasOwn(methods, key)) {
4652
+ warn(
4653
+ ("Method \"" + key + "\" has already been defined as a data property."),
4654
+ vm
4655
+ );
4656
+ }
4657
+ }
4658
+ if (props && hasOwn(props, key)) {
4650
4659
  warn(
4651
- 'Avoid using non-primitive value as key, ' +
4652
- 'use string/number value instead.',
4653
- context
4660
+ "The data property \"" + key + "\" is already declared as a prop. " +
4661
+ "Use prop default value instead.",
4662
+ vm
4654
4663
  );
4664
+ } else if (!isReserved(key)) {
4665
+ proxy(vm, "_data", key);
4655
4666
  }
4656
4667
  }
4657
- // support single function children as default scoped slot
4658
- if (Array.isArray(children) &&
4659
- typeof children[0] === 'function'
4660
- ) {
4661
- data = data || {};
4662
- data.scopedSlots = { default: children[0] };
4663
- children.length = 0;
4664
- }
4665
- if (normalizationType === ALWAYS_NORMALIZE) {
4666
- children = normalizeChildren(children);
4667
- } else if (normalizationType === SIMPLE_NORMALIZE) {
4668
- children = simpleNormalizeChildren(children);
4668
+ // observe data
4669
+ observe(data, true /* asRootData */);
4670
+ }
4671
+
4672
+ function getData (data, vm) {
4673
+ // #7573 disable dep collection when invoking data getters
4674
+ pushTarget();
4675
+ try {
4676
+ return data.call(vm, vm)
4677
+ } catch (e) {
4678
+ handleError(e, vm, "data()");
4679
+ return {}
4680
+ } finally {
4681
+ popTarget();
4669
4682
  }
4670
- var vnode, ns;
4671
- if (typeof tag === 'string') {
4672
- var Ctor;
4673
- ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
4674
- if (config.isReservedTag(tag)) {
4675
- // platform built-in elements
4676
- vnode = new VNode(
4677
- config.parsePlatformTagName(tag), data, children,
4678
- undefined, undefined, context
4683
+ }
4684
+
4685
+ var computedWatcherOptions = { lazy: true };
4686
+
4687
+ function initComputed (vm, computed) {
4688
+ // $flow-disable-line
4689
+ var watchers = vm._computedWatchers = Object.create(null);
4690
+ // computed properties are just getters during SSR
4691
+ var isSSR = isServerRendering();
4692
+
4693
+ for (var key in computed) {
4694
+ var userDef = computed[key];
4695
+ var getter = typeof userDef === 'function' ? userDef : userDef.get;
4696
+ if (getter == null) {
4697
+ warn(
4698
+ ("Getter is missing for computed property \"" + key + "\"."),
4699
+ vm
4679
4700
  );
4680
- } else if ((!data || !data.pre) && isDef(Ctor = resolveAsset(context.$options, 'components', tag))) {
4681
- // component
4682
- vnode = createComponent(Ctor, data, context, children, tag);
4683
- } else {
4684
- // unknown or unlisted namespaced elements
4685
- // check at runtime because it may get assigned a namespace when its
4686
- // parent normalizes children
4687
- vnode = new VNode(
4688
- tag, data, children,
4689
- undefined, undefined, context
4701
+ }
4702
+
4703
+ if (!isSSR) {
4704
+ // create internal watcher for the computed property.
4705
+ watchers[key] = new Watcher(
4706
+ vm,
4707
+ getter || noop,
4708
+ noop,
4709
+ computedWatcherOptions
4690
4710
  );
4691
4711
  }
4692
- } else {
4693
- // direct component options / constructor
4694
- vnode = createComponent(tag, data, context, children);
4712
+
4713
+ // component-defined computed properties are already defined on the
4714
+ // component prototype. We only need to define computed properties defined
4715
+ // at instantiation here.
4716
+ if (!(key in vm)) {
4717
+ defineComputed(vm, key, userDef);
4718
+ } else {
4719
+ if (key in vm.$data) {
4720
+ warn(("The computed property \"" + key + "\" is already defined in data."), vm);
4721
+ } else if (vm.$options.props && key in vm.$options.props) {
4722
+ warn(("The computed property \"" + key + "\" is already defined as a prop."), vm);
4723
+ }
4724
+ }
4695
4725
  }
4696
- if (Array.isArray(vnode)) {
4697
- return vnode
4698
- } else if (isDef(vnode)) {
4699
- if (isDef(ns)) { applyNS(vnode, ns); }
4700
- if (isDef(data)) { registerDeepBindings(data); }
4701
- return vnode
4726
+ }
4727
+
4728
+ function defineComputed (
4729
+ target,
4730
+ key,
4731
+ userDef
4732
+ ) {
4733
+ var shouldCache = !isServerRendering();
4734
+ if (typeof userDef === 'function') {
4735
+ sharedPropertyDefinition.get = shouldCache
4736
+ ? createComputedGetter(key)
4737
+ : createGetterInvoker(userDef);
4738
+ sharedPropertyDefinition.set = noop;
4702
4739
  } else {
4703
- return createEmptyVNode()
4740
+ sharedPropertyDefinition.get = userDef.get
4741
+ ? shouldCache && userDef.cache !== false
4742
+ ? createComputedGetter(key)
4743
+ : createGetterInvoker(userDef.get)
4744
+ : noop;
4745
+ sharedPropertyDefinition.set = userDef.set || noop;
4746
+ }
4747
+ if (sharedPropertyDefinition.set === noop) {
4748
+ sharedPropertyDefinition.set = function () {
4749
+ warn(
4750
+ ("Computed property \"" + key + "\" was assigned to but it has no setter."),
4751
+ this
4752
+ );
4753
+ };
4704
4754
  }
4755
+ Object.defineProperty(target, key, sharedPropertyDefinition);
4705
4756
  }
4706
4757
 
4707
- function applyNS (vnode, ns, force) {
4708
- vnode.ns = ns;
4709
- if (vnode.tag === 'foreignObject') {
4710
- // use default namespace inside foreignObject
4711
- ns = undefined;
4712
- force = true;
4713
- }
4714
- if (isDef(vnode.children)) {
4715
- for (var i = 0, l = vnode.children.length; i < l; i++) {
4716
- var child = vnode.children[i];
4717
- if (isDef(child.tag) && (
4718
- isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
4719
- applyNS(child, ns, force);
4758
+ function createComputedGetter (key) {
4759
+ return function computedGetter () {
4760
+ var watcher = this._computedWatchers && this._computedWatchers[key];
4761
+ if (watcher) {
4762
+ if (watcher.dirty) {
4763
+ watcher.evaluate();
4764
+ }
4765
+ if (Dep.target) {
4766
+ watcher.depend();
4720
4767
  }
4768
+ return watcher.value
4721
4769
  }
4722
4770
  }
4723
4771
  }
4724
4772
 
4725
- // ref #5318
4726
- // necessary to ensure parent re-render when deep bindings like :style and
4727
- // :class are used on slot nodes
4728
- function registerDeepBindings (data) {
4729
- if (isObject(data.style)) {
4730
- traverse(data.style);
4731
- }
4732
- if (isObject(data.class)) {
4733
- traverse(data.class);
4773
+ function createGetterInvoker(fn) {
4774
+ return function computedGetter () {
4775
+ return fn.call(this, this)
4734
4776
  }
4735
4777
  }
4736
4778
 
4737
- /* */
4738
-
4739
- function initRender (vm) {
4740
- vm._vnode = null; // the root of the child tree
4741
- vm._staticTrees = null; // v-once cached trees
4742
- var options = vm.$options;
4743
- var parentVnode = vm.$vnode = options._parentVnode; // the placeholder node in parent tree
4744
- var renderContext = parentVnode && parentVnode.context;
4745
- vm.$slots = resolveSlots(options._renderChildren, renderContext);
4746
- vm.$scopedSlots = emptyObject;
4747
- // bind the createElement fn to this instance
4748
- // so that we get proper render context inside it.
4749
- // args order: tag, data, children, normalizationType, alwaysNormalize
4750
- // internal version is used by render functions compiled from templates
4751
- vm._c = function (a, b, c, d) { return createElement(vm, a, b, c, d, false); };
4752
- // normalization is always applied for the public version, used in
4753
- // user-written render functions.
4754
- vm.$createElement = function (a, b, c, d) { return createElement(vm, a, b, c, d, true); };
4779
+ function initMethods (vm, methods) {
4780
+ var props = vm.$options.props;
4781
+ for (var key in methods) {
4782
+ {
4783
+ if (typeof methods[key] !== 'function') {
4784
+ warn(
4785
+ "Method \"" + key + "\" has type \"" + (typeof methods[key]) + "\" in the component definition. " +
4786
+ "Did you reference the function correctly?",
4787
+ vm
4788
+ );
4789
+ }
4790
+ if (props && hasOwn(props, key)) {
4791
+ warn(
4792
+ ("Method \"" + key + "\" has already been defined as a prop."),
4793
+ vm
4794
+ );
4795
+ }
4796
+ if ((key in vm) && isReserved(key)) {
4797
+ warn(
4798
+ "Method \"" + key + "\" conflicts with an existing Vue instance method. " +
4799
+ "Avoid defining component methods that start with _ or $."
4800
+ );
4801
+ }
4802
+ }
4803
+ vm[key] = typeof methods[key] !== 'function' ? noop : bind(methods[key], vm);
4804
+ }
4805
+ }
4755
4806
 
4756
- // $attrs & $listeners are exposed for easier HOC creation.
4757
- // they need to be reactive so that HOCs using them are always updated
4758
- var parentData = parentVnode && parentVnode.data;
4807
+ function initWatch (vm, watch) {
4808
+ for (var key in watch) {
4809
+ var handler = watch[key];
4810
+ if (Array.isArray(handler)) {
4811
+ for (var i = 0; i < handler.length; i++) {
4812
+ createWatcher(vm, key, handler[i]);
4813
+ }
4814
+ } else {
4815
+ createWatcher(vm, key, handler);
4816
+ }
4817
+ }
4818
+ }
4759
4819
 
4760
- /* istanbul ignore else */
4761
- {
4762
- defineReactive$$1(vm, '$attrs', parentData && parentData.attrs || emptyObject, function () {
4763
- !isUpdatingChildComponent && warn("$attrs is readonly.", vm);
4764
- }, true);
4765
- defineReactive$$1(vm, '$listeners', options._parentListeners || emptyObject, function () {
4766
- !isUpdatingChildComponent && warn("$listeners is readonly.", vm);
4767
- }, true);
4820
+ function createWatcher (
4821
+ vm,
4822
+ expOrFn,
4823
+ handler,
4824
+ options
4825
+ ) {
4826
+ if (isPlainObject(handler)) {
4827
+ options = handler;
4828
+ handler = handler.handler;
4829
+ }
4830
+ if (typeof handler === 'string') {
4831
+ handler = vm[handler];
4768
4832
  }
4833
+ return vm.$watch(expOrFn, handler, options)
4769
4834
  }
4770
4835
 
4771
- function renderMixin (Vue) {
4772
- // install runtime convenience helpers
4773
- installRenderHelpers(Vue.prototype);
4836
+ function stateMixin (Vue) {
4837
+ // flow somehow has problems with directly declared definition object
4838
+ // when using Object.defineProperty, so we have to procedurally build up
4839
+ // the object here.
4840
+ var dataDef = {};
4841
+ dataDef.get = function () { return this._data };
4842
+ var propsDef = {};
4843
+ propsDef.get = function () { return this._props };
4844
+ {
4845
+ dataDef.set = function () {
4846
+ warn(
4847
+ 'Avoid replacing instance root $data. ' +
4848
+ 'Use nested data properties instead.',
4849
+ this
4850
+ );
4851
+ };
4852
+ propsDef.set = function () {
4853
+ warn("$props is readonly.", this);
4854
+ };
4855
+ }
4856
+ Object.defineProperty(Vue.prototype, '$data', dataDef);
4857
+ Object.defineProperty(Vue.prototype, '$props', propsDef);
4774
4858
 
4775
- Vue.prototype.$nextTick = function (fn) {
4776
- return nextTick(fn, this)
4777
- };
4859
+ Vue.prototype.$set = set;
4860
+ Vue.prototype.$delete = del;
4778
4861
 
4779
- Vue.prototype._render = function () {
4862
+ Vue.prototype.$watch = function (
4863
+ expOrFn,
4864
+ cb,
4865
+ options
4866
+ ) {
4780
4867
  var vm = this;
4781
- var ref = vm.$options;
4782
- var render = ref.render;
4783
- var _parentVnode = ref._parentVnode;
4784
-
4785
- if (_parentVnode) {
4786
- vm.$scopedSlots = normalizeScopedSlots(
4787
- _parentVnode.data.scopedSlots,
4788
- vm.$slots
4789
- );
4868
+ if (isPlainObject(cb)) {
4869
+ return createWatcher(vm, expOrFn, cb, options)
4790
4870
  }
4791
-
4792
- // set parent vnode. this allows render functions to have access
4793
- // to the data on the placeholder node.
4794
- vm.$vnode = _parentVnode;
4795
- // render self
4796
- var vnode;
4797
- try {
4798
- vnode = render.call(vm._renderProxy, vm.$createElement);
4799
- } catch (e) {
4800
- handleError(e, vm, "render");
4801
- // return error render result,
4802
- // or previous vnode to prevent render error causing blank component
4803
- /* istanbul ignore else */
4804
- if (vm.$options.renderError) {
4805
- try {
4806
- vnode = vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e);
4807
- } catch (e) {
4808
- handleError(e, vm, "renderError");
4809
- vnode = vm._vnode;
4810
- }
4811
- } else {
4812
- vnode = vm._vnode;
4871
+ options = options || {};
4872
+ options.user = true;
4873
+ var watcher = new Watcher(vm, expOrFn, cb, options);
4874
+ if (options.immediate) {
4875
+ try {
4876
+ cb.call(vm, watcher.value);
4877
+ } catch (error) {
4878
+ handleError(error, vm, ("callback for immediate watcher \"" + (watcher.expression) + "\""));
4813
4879
  }
4814
4880
  }
4815
- // if the returned array contains only a single node, allow it
4816
- if (Array.isArray(vnode) && vnode.length === 1) {
4817
- vnode = vnode[0];
4818
- }
4819
- // return empty vnode in case the render function errored out
4820
- if (!(vnode instanceof VNode)) {
4821
- if (Array.isArray(vnode)) {
4822
- warn(
4823
- 'Multiple root nodes returned from render function. Render function ' +
4824
- 'should return a single root node.',
4825
- vm
4826
- );
4827
- }
4828
- vnode = createEmptyVNode();
4881
+ return function unwatchFn () {
4882
+ watcher.teardown();
4829
4883
  }
4830
- // set parent
4831
- vnode.parent = _parentVnode;
4832
- return vnode
4833
4884
  };
4834
4885
  }
4835
4886
 
@@ -5323,7 +5374,7 @@
5323
5374
  value: FunctionalRenderContext
5324
5375
  });
5325
5376
 
5326
- Vue.version = '2.6.2';
5377
+ Vue.version = '2.6.6';
5327
5378
 
5328
5379
  /* */
5329
5380
 
@@ -6748,6 +6799,11 @@
6748
6799
  }
6749
6800
  }
6750
6801
 
6802
+ // #9446: Firefox <= 53 (in particular, ESR 52) has incorrect Event.timeStamp
6803
+ // implementation and does not fire microtasks in between event propagation, so
6804
+ // safe to exclude.
6805
+ var useMicrotaskFix = isUsingMicroTask && !(isFF && Number(isFF[1]) <= 53);
6806
+
6751
6807
  function add$1 (
6752
6808
  name,
6753
6809
  handler,
@@ -6760,11 +6816,24 @@
6760
6816
  // the solution is simple: we save the timestamp when a handler is attached,
6761
6817
  // and the handler would only fire if the event passed to it was fired
6762
6818
  // AFTER it was attached.
6763
- if (isUsingMicroTask) {
6819
+ if (useMicrotaskFix) {
6764
6820
  var attachedTimestamp = currentFlushTimestamp;
6765
6821
  var original = handler;
6766
6822
  handler = original._wrapper = function (e) {
6767
- if (e.timeStamp >= attachedTimestamp) {
6823
+ if (
6824
+ // no bubbling, should always fire.
6825
+ // this is just a safety net in case event.timeStamp is unreliable in
6826
+ // certain weird environments...
6827
+ e.target === e.currentTarget ||
6828
+ // event is fired after handler attachment
6829
+ e.timeStamp >= attachedTimestamp ||
6830
+ // #9462 bail for iOS 9 bug: event.timeStamp is 0 after history.pushState
6831
+ e.timeStamp === 0 ||
6832
+ // #9448 bail if event is fired in another document in a multi-page
6833
+ // electron/nw.js app, since event.timeStamp will be using a different
6834
+ // starting reference
6835
+ e.target.ownerDocument !== document
6836
+ ) {
6768
6837
  return original.apply(this, arguments)
6769
6838
  }
6770
6839
  };