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