|
@@ -1,42 +1,33 @@
|
|
/**
|
|
/**
|
|
- * vuex v3.1.3
|
|
|
|
|
|
+ * vuex v4.0.0-alpha.1
|
|
* (c) 2020 Evan You
|
|
* (c) 2020 Evan You
|
|
* @license MIT
|
|
* @license MIT
|
|
*/
|
|
*/
|
|
-function applyMixin (Vue) {
|
|
|
|
- var version = Number(Vue.version.split('.')[0]);
|
|
|
|
|
|
+import { inject, watch, computed, reactive } from 'vue';
|
|
|
|
|
|
- if (version >= 2) {
|
|
|
|
- Vue.mixin({ beforeCreate: vuexInit });
|
|
|
|
- } else {
|
|
|
|
- // override init and inject vuex init procedure
|
|
|
|
- // for 1.x backwards compatibility.
|
|
|
|
- var _init = Vue.prototype._init;
|
|
|
|
- Vue.prototype._init = function (options) {
|
|
|
|
- if ( options === void 0 ) options = {};
|
|
|
|
-
|
|
|
|
- options.init = options.init
|
|
|
|
- ? [vuexInit].concat(options.init)
|
|
|
|
- : vuexInit;
|
|
|
|
- _init.call(this, options);
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+var storeKey = 'store';
|
|
|
|
+
|
|
|
|
+function useStore (key) {
|
|
|
|
+ if ( key === void 0 ) key = null;
|
|
|
|
+
|
|
|
|
+ return inject(key !== null ? key : storeKey)
|
|
|
|
+}
|
|
|
|
|
|
- /**
|
|
|
|
- * Vuex init hook, injected into each instances init hooks list.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- function vuexInit () {
|
|
|
|
- var options = this.$options;
|
|
|
|
- // store injection
|
|
|
|
- if (options.store) {
|
|
|
|
- this.$store = typeof options.store === 'function'
|
|
|
|
- ? options.store()
|
|
|
|
- : options.store;
|
|
|
|
- } else if (options.parent && options.parent.$store) {
|
|
|
|
- this.$store = options.parent.$store;
|
|
|
|
|
|
+function applyMixin (app, store, injectKey) {
|
|
|
|
+ app.provide(injectKey || storeKey, store);
|
|
|
|
+
|
|
|
|
+ // TODO: Refactor this to use `provide/inject`. It's currently
|
|
|
|
+ // not possible because Vue 3 doesn't work with `$` prefixed
|
|
|
|
+ // `provide/inject` at the moment.
|
|
|
|
+ app.mixin({
|
|
|
|
+ beforeCreate: function beforeCreate () {
|
|
|
|
+ if (!this.parent) {
|
|
|
|
+ this.$store = typeof store === 'function' ? store() : store;
|
|
|
|
+ } else {
|
|
|
|
+ this.$store = this.parent.$options.$store;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
var target = typeof window !== 'undefined'
|
|
var target = typeof window !== 'undefined'
|
|
@@ -289,21 +280,28 @@ function makeAssertionMessage (path, key, type, value, expected) {
|
|
return buf
|
|
return buf
|
|
}
|
|
}
|
|
|
|
|
|
-var Vue; // bind on install
|
|
|
|
|
|
+// let Vue // bind on install
|
|
|
|
+
|
|
|
|
+function createStore (options) {
|
|
|
|
+ return new Store(options)
|
|
|
|
+}
|
|
|
|
|
|
var Store = function Store (options) {
|
|
var Store = function Store (options) {
|
|
var this$1 = this;
|
|
var this$1 = this;
|
|
if ( options === void 0 ) options = {};
|
|
if ( options === void 0 ) options = {};
|
|
|
|
|
|
|
|
+ // TODO: Bring back this one if needed.
|
|
|
|
+ //
|
|
// Auto install if it is not done yet and `window` has `Vue`.
|
|
// Auto install if it is not done yet and `window` has `Vue`.
|
|
// To allow users to avoid auto-installation in some cases,
|
|
// To allow users to avoid auto-installation in some cases,
|
|
// this code should be placed here. See #731
|
|
// this code should be placed here. See #731
|
|
- if (!Vue && typeof window !== 'undefined' && window.Vue) {
|
|
|
|
- install(window.Vue);
|
|
|
|
- }
|
|
|
|
|
|
+ // if (!Vue && typeof window !== 'undefined' && window.Vue) {
|
|
|
|
+ // install(window.Vue)
|
|
|
|
+ // }
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
- assert(Vue, "must call Vue.use(Vuex) before creating a store instance.");
|
|
|
|
|
|
+ // TODO: Maybe we can remove this depending on the new implementation.
|
|
|
|
+ // assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`)
|
|
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
|
|
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
|
|
assert(this instanceof Store, "store must be called with the new operator.");
|
|
assert(this instanceof Store, "store must be called with the new operator.");
|
|
}
|
|
}
|
|
@@ -320,7 +318,6 @@ var Store = function Store (options) {
|
|
this._modules = new ModuleCollection(options);
|
|
this._modules = new ModuleCollection(options);
|
|
this._modulesNamespaceMap = Object.create(null);
|
|
this._modulesNamespaceMap = Object.create(null);
|
|
this._subscribers = [];
|
|
this._subscribers = [];
|
|
- this._watcherVM = new Vue();
|
|
|
|
this._makeLocalGettersCache = Object.create(null);
|
|
this._makeLocalGettersCache = Object.create(null);
|
|
|
|
|
|
// bind commit and dispatch to self
|
|
// bind commit and dispatch to self
|
|
@@ -352,7 +349,7 @@ var Store = function Store (options) {
|
|
// apply plugins
|
|
// apply plugins
|
|
plugins.forEach(function (plugin) { return plugin(this$1); });
|
|
plugins.forEach(function (plugin) { return plugin(this$1); });
|
|
|
|
|
|
- var useDevtools = options.devtools !== undefined ? options.devtools : Vue.config.devtools;
|
|
|
|
|
|
+ var useDevtools = options.devtools !== undefined ? options.devtools : /* Vue.config.devtools */ true;
|
|
if (useDevtools) {
|
|
if (useDevtools) {
|
|
devtoolPlugin(this);
|
|
devtoolPlugin(this);
|
|
}
|
|
}
|
|
@@ -360,6 +357,23 @@ var Store = function Store (options) {
|
|
|
|
|
|
var prototypeAccessors$1 = { state: { configurable: true } };
|
|
var prototypeAccessors$1 = { state: { configurable: true } };
|
|
|
|
|
|
|
|
+Store.prototype.install = function install (app, injectKey) {
|
|
|
|
+ // TODO: Removing double install check for now. Maybe we can bring this
|
|
|
|
+ // feature back again if needed.
|
|
|
|
+ //
|
|
|
|
+ // if (Vue && _Vue === Vue) {
|
|
|
|
+ // if (process.env.NODE_ENV !== 'production') {
|
|
|
|
+ // console.error(
|
|
|
|
+ // '[vuex] already installed. Vue.use(Vuex) should be called only once.'
|
|
|
|
+ // )
|
|
|
|
+ // }
|
|
|
|
+ // return
|
|
|
|
+ // }
|
|
|
|
+ // Vue = _Vue
|
|
|
|
+
|
|
|
|
+ applyMixin(app, this, injectKey);
|
|
|
|
+};
|
|
|
|
+
|
|
prototypeAccessors$1.state.get = function () {
|
|
prototypeAccessors$1.state.get = function () {
|
|
return this._vm._data.$$state
|
|
return this._vm._data.$$state
|
|
};
|
|
};
|
|
@@ -465,13 +479,13 @@ Store.prototype.subscribeAction = function subscribeAction (fn) {
|
|
return genericSubscribe(subs, this._actionSubscribers)
|
|
return genericSubscribe(subs, this._actionSubscribers)
|
|
};
|
|
};
|
|
|
|
|
|
-Store.prototype.watch = function watch (getter, cb, options) {
|
|
|
|
|
|
+Store.prototype.watch = function watch$1 (getter, cb, options) {
|
|
var this$1 = this;
|
|
var this$1 = this;
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
assert(typeof getter === 'function', "store.watch only accepts a function.");
|
|
assert(typeof getter === 'function', "store.watch only accepts a function.");
|
|
}
|
|
}
|
|
- return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options)
|
|
|
|
|
|
+ return watch(function () { return getter(this$1.state, this$1.getters); }, cb, Object.assign({}, options))
|
|
};
|
|
};
|
|
|
|
|
|
Store.prototype.replaceState = function replaceState (state) {
|
|
Store.prototype.replaceState = function replaceState (state) {
|
|
@@ -510,7 +524,7 @@ Store.prototype.unregisterModule = function unregisterModule (path) {
|
|
this._modules.unregister(path);
|
|
this._modules.unregister(path);
|
|
this._withCommit(function () {
|
|
this._withCommit(function () {
|
|
var parentState = getNestedState(this$1.state, path.slice(0, -1));
|
|
var parentState = getNestedState(this$1.state, path.slice(0, -1));
|
|
- Vue.delete(parentState, path[path.length - 1]);
|
|
|
|
|
|
+ delete parentState[path[path.length - 1]];
|
|
});
|
|
});
|
|
resetStore(this);
|
|
resetStore(this);
|
|
};
|
|
};
|
|
@@ -561,30 +575,42 @@ function resetStoreVM (store, state, hot) {
|
|
// reset local getters cache
|
|
// reset local getters cache
|
|
store._makeLocalGettersCache = Object.create(null);
|
|
store._makeLocalGettersCache = Object.create(null);
|
|
var wrappedGetters = store._wrappedGetters;
|
|
var wrappedGetters = store._wrappedGetters;
|
|
- var computed = {};
|
|
|
|
|
|
+ var computedObj = {};
|
|
forEachValue(wrappedGetters, function (fn, key) {
|
|
forEachValue(wrappedGetters, function (fn, key) {
|
|
|
|
+ // TODO: Refactor following code and comment. We can simplify many things
|
|
|
|
+ // using computed function.
|
|
|
|
+ //
|
|
// use computed to leverage its lazy-caching mechanism
|
|
// use computed to leverage its lazy-caching mechanism
|
|
// direct inline function use will lead to closure preserving oldVm.
|
|
// direct inline function use will lead to closure preserving oldVm.
|
|
// using partial to return function with only arguments preserved in closure environment.
|
|
// using partial to return function with only arguments preserved in closure environment.
|
|
- computed[key] = partial(fn, store);
|
|
|
|
|
|
+ computedObj[key] = partial(fn, store);
|
|
Object.defineProperty(store.getters, key, {
|
|
Object.defineProperty(store.getters, key, {
|
|
- get: function () { return store._vm[key]; },
|
|
|
|
|
|
+ get: function () { return computed(function () { return computedObj[key](); }).value; },
|
|
enumerable: true // for local getters
|
|
enumerable: true // for local getters
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ // TODO: Bring back this if it's still needed.
|
|
|
|
+ //
|
|
// use a Vue instance to store the state tree
|
|
// use a Vue instance to store the state tree
|
|
// suppress warnings just in case the user has added
|
|
// suppress warnings just in case the user has added
|
|
// some funky global mixins
|
|
// some funky global mixins
|
|
- var silent = Vue.config.silent;
|
|
|
|
- Vue.config.silent = true;
|
|
|
|
- store._vm = new Vue({
|
|
|
|
- data: {
|
|
|
|
|
|
+ // const silent = Vue.config.silent
|
|
|
|
+ // Vue.config.silent = true
|
|
|
|
+
|
|
|
|
+ // TODO: Refactor the code and remove this comment.
|
|
|
|
+ //
|
|
|
|
+ // New impl with reactive. Defining redundunt keys to make it as close as
|
|
|
|
+ // the old impl api.
|
|
|
|
+ store._vm = reactive({
|
|
|
|
+ _data: {
|
|
$$state: state
|
|
$$state: state
|
|
- },
|
|
|
|
- computed: computed
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- Vue.config.silent = silent;
|
|
|
|
|
|
+
|
|
|
|
+ // TODO: Bring back maybe?
|
|
|
|
+ //
|
|
|
|
+ // Vue.config.silent = silent
|
|
|
|
|
|
// enable strict mode for new vm
|
|
// enable strict mode for new vm
|
|
if (store.strict) {
|
|
if (store.strict) {
|
|
@@ -599,7 +625,8 @@ function resetStoreVM (store, state, hot) {
|
|
oldVm._data.$$state = null;
|
|
oldVm._data.$$state = null;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- Vue.nextTick(function () { return oldVm.$destroy(); });
|
|
|
|
|
|
+ // TODO: I think we don't need this anymore since we're not using vm?
|
|
|
|
+ // Vue.nextTick(() => oldVm.$destroy())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -627,7 +654,7 @@ function installModule (store, rootState, path, module, hot) {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Vue.set(parentState, moduleName, module.state);
|
|
|
|
|
|
+ parentState[moduleName] = module.state;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -788,11 +815,11 @@ function registerGetter (store, type, rawGetter, local) {
|
|
}
|
|
}
|
|
|
|
|
|
function enableStrictMode (store) {
|
|
function enableStrictMode (store) {
|
|
- store._vm.$watch(function () { return this._data.$$state }, function () {
|
|
|
|
|
|
+ watch(function () { return store._vm._data.$$state; }, function () {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
assert(store._committing, "do not mutate vuex store state outside mutation handlers.");
|
|
assert(store._committing, "do not mutate vuex store state outside mutation handlers.");
|
|
}
|
|
}
|
|
- }, { deep: true, sync: true });
|
|
|
|
|
|
+ }, { deep: true, flush: 'sync' });
|
|
}
|
|
}
|
|
|
|
|
|
function getNestedState (state, path) {
|
|
function getNestedState (state, path) {
|
|
@@ -813,19 +840,6 @@ function unifyObjectStyle (type, payload, options) {
|
|
return { type: type, payload: payload, options: options }
|
|
return { type: type, payload: payload, options: options }
|
|
}
|
|
}
|
|
|
|
|
|
-function install (_Vue) {
|
|
|
|
- if (Vue && _Vue === Vue) {
|
|
|
|
- if (process.env.NODE_ENV !== 'production') {
|
|
|
|
- console.error(
|
|
|
|
- '[vuex] already installed. Vue.use(Vuex) should be called only once.'
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- Vue = _Vue;
|
|
|
|
- applyMixin(Vue);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Reduce the code which written in Vue.js for getting the state.
|
|
* Reduce the code which written in Vue.js for getting the state.
|
|
* @param {String} [namespace] - Module's namespace
|
|
* @param {String} [namespace] - Module's namespace
|
|
@@ -1037,9 +1051,10 @@ function getModuleByNamespace (store, helper, namespace) {
|
|
}
|
|
}
|
|
|
|
|
|
var index_esm = {
|
|
var index_esm = {
|
|
|
|
+ version: '4.0.0-alpha.1',
|
|
|
|
+ createStore: createStore,
|
|
Store: Store,
|
|
Store: Store,
|
|
- install: install,
|
|
|
|
- version: '3.1.3',
|
|
|
|
|
|
+ useStore: useStore,
|
|
mapState: mapState,
|
|
mapState: mapState,
|
|
mapMutations: mapMutations,
|
|
mapMutations: mapMutations,
|
|
mapGetters: mapGetters,
|
|
mapGetters: mapGetters,
|
|
@@ -1048,4 +1063,4 @@ var index_esm = {
|
|
};
|
|
};
|
|
|
|
|
|
export default index_esm;
|
|
export default index_esm;
|
|
-export { Store, install, mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers };
|
|
|
|
|
|
+export { createStore, Store, useStore, mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers };
|