direct-vuex
Advanced tools
Comparing version 0.12.1 to 1.0.0-rc3
@@ -1,5 +0,5 @@ | ||
import Vuex from 'vuex'; | ||
import { createStore } from 'vuex'; | ||
function createDirectStore(options) { | ||
const original = new Vuex.Store(options); | ||
const original = createStore(options); | ||
const store = { | ||
@@ -6,0 +6,0 @@ get state() { |
@@ -1,1 +0,1 @@ | ||
import Vuex from"vuex";function createDirectStore(t){const e=new Vuex.Store(t),o={get state(){return e.state},getters:toDirectGetters(t,e.getters),commit:toDirectCommit(t,e.commit),dispatch:toDirectDispatch(t,e.dispatch),original:e};return e.direct=o,{store:o,rootGetterContext:([e,o])=>getModuleGetterContext([e,o,e,o],t,t),moduleGetterContext:(e,o)=>getModuleGetterContext(e,o,t),rootActionContext:e=>getModuleActionContext(e,t,t),moduleActionContext:(e,o)=>getModuleActionContext(e,o,t)}}function localGetterContext([t,e],o){return getModuleGetterContext([t,e,void 0,void 0],o)}function localActionContext(t,e){return getModuleActionContext(t,e)}function defineModule(t){return t}function defineModules(){return t=>t}function defineGetters(){return t=>t}function defineMutations(){return t=>t}function defineActions(t){return t}const createModule=obsolete(defineModule,"createModule","defineModule"),createModules=obsolete(defineModules,"createModules","defineModules"),createGetters=obsolete(defineGetters,"createGetters","defineGetters"),createMutations=obsolete(defineMutations,"createMutations","defineMutations"),createActions=obsolete(defineActions,"createActions","defineActions");function obsolete(t,e,o){return(...r)=>(console.warn(`Function '${e}' is obsolete, please use '${o}'.`),t(...r))}var directVuex={createDirectStore:createDirectStore,defineModule:defineModule,defineModules:defineModules,defineGetters:defineGetters,defineMutations:defineMutations,defineActions:defineActions,localGetterContext:localGetterContext,localActionContext:localActionContext,createModule:createModule,createModules:createModules,createGetters:createGetters,createMutations:createMutations,createActions:createActions};const gettersCache=new WeakMap;function toDirectGetters(t,e){let o=gettersCache.get(e);return o||(o=gettersFromOptions({},t,e),gettersCache.set(e,o)),o}function gettersFromOptions(t,e,o,r=[]){if(e.getters&&createDirectGetters(t,e.getters,o,r),e.modules)for(const n of Object.keys(e.modules)){const c=e.modules[n];c.namespaced?t[n]=gettersFromOptions({},c,o,[...r,n]):gettersFromOptions(t,c,o,r)}return t}function createDirectGetters(t,e,o,r){const n=r&&0!==r.length?r.join("/")+"/":"";for(const r of Object.keys(e))Object.defineProperties(t,{[r]:{get:()=>o[`${n}${r}`]}})}const commitCache=new WeakMap;function toDirectCommit(t,e){let o=commitCache.get(e);return o||(o=commitFromOptions({},t,e),commitCache.set(e,o)),o}const rootCommitCache=new WeakMap;function toDirectRootCommit(t,e){let o=rootCommitCache.get(e);if(!o){o=commitFromOptions({},t,(t,o)=>e(t,o,{root:!0})),rootCommitCache.set(e,o)}return o}function commitFromOptions(t,e,o,r=[]){if(e.mutations&&createDirectMutations(t,e.mutations,o,r),e.modules)for(const n of Object.keys(e.modules)){const c=e.modules[n];c.namespaced?t[n]=commitFromOptions({},c,o,[...r,n]):commitFromOptions(t,c,o,r)}return t}function createDirectMutations(t,e,o,r){const n=r&&0!==r.length?r.join("/")+"/":"";for(const r of Object.keys(e))t[r]=t=>o(`${n}${r}`,t)}const dispatchCache=new WeakMap;function toDirectDispatch(t,e){let o=dispatchCache.get(e);return o||(o=dispatchFromOptions({},t,e),dispatchCache.set(e,o)),o}const rootDispatchCache=new WeakMap;function toDirectRootDispatch(t,e){let o=rootDispatchCache.get(e);if(!o){o=dispatchFromOptions({},t,(t,o)=>e(t,o,{root:!0})),rootDispatchCache.set(e,o)}return o}function dispatchFromOptions(t,e,o,r=[]){if(e.actions&&createDirectActions(t,e.actions,o,r),e.modules)for(const n of Object.keys(e.modules)){const c=e.modules[n];c.namespaced?t[n]=dispatchFromOptions({},c,o,[...r,n]):dispatchFromOptions(t,c,o,r)}return t}function createDirectActions(t,e,o,r){const n=r&&0!==r.length?r.join("/")+"/":"";for(const r of Object.keys(e))t[r]=t=>o(`${n}${r}`,t)}const getterContextCache=new WeakMap;function getModuleGetterContext(t,e,o){const[r,n,c,i]=t;let s=actionContextCache.get(r);return s||(s=o?{get rootState(){return c},get rootGetters(){return toDirectGetters(o,i)},get state(){return r},get getters(){return toDirectGetters(e,n)}}:{get state(){return r},get getters(){return toDirectGetters(e,n)}},r&&getterContextCache.set(r,s)),s}const actionContextCache=new WeakMap;function getModuleActionContext(t,e,o){let r=actionContextCache.get(t.state);return r||(r=o?{get rootState(){return t.rootState},get rootGetters(){return toDirectGetters(o,t.rootGetters)},get rootCommit(){return toDirectRootCommit(o,t.commit)},get rootDispatch(){return toDirectRootDispatch(o,t.dispatch)},get state(){return t.state},get getters(){return toDirectGetters(e,t.getters)},get commit(){return toDirectCommit(e,t.commit)},get dispatch(){return toDirectDispatch(e,t.dispatch)}}:{get state(){return t.state},get getters(){return toDirectGetters(e,t.getters)},get commit(){return toDirectCommit(e,t.commit)},get dispatch(){return toDirectDispatch(e,t.dispatch)}},t.state&&actionContextCache.set(t.state,r)),r}export default directVuex;export{createActions,createDirectStore,createGetters,createModule,createModules,createMutations,defineActions,defineGetters,defineModule,defineModules,defineMutations,localActionContext,localGetterContext}; | ||
undefined |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vuex')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vuex'], factory) : | ||
(global = global || self, factory(global.DirectVuex = {}, global.Vuex)); | ||
}(this, (function (exports, Vuex) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.DirectVuex = {}, global.Vuex)); | ||
}(this, (function (exports, vuex) { 'use strict'; | ||
Vuex = Vuex && Object.prototype.hasOwnProperty.call(Vuex, 'default') ? Vuex['default'] : Vuex; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
}; | ||
function createDirectStore(options) { | ||
var original = new Vuex.Store(options); | ||
var original = vuex.createStore(options); | ||
var store = { | ||
@@ -104,3 +100,3 @@ get state() { | ||
if (moduleOptions.namespaced) | ||
result[moduleName] = gettersFromOptions({}, moduleOptions, originalGetters, __spreadArrays(hierarchy, [moduleName])); | ||
result[moduleName] = gettersFromOptions({}, moduleOptions, originalGetters, __spreadArray(__spreadArray([], hierarchy), [moduleName])); | ||
else | ||
@@ -115,8 +111,8 @@ gettersFromOptions(result, moduleOptions, originalGetters, hierarchy); | ||
var _loop_1 = function (name_1) { | ||
var _a; | ||
Object.defineProperties(result, (_a = {}, | ||
_a[name_1] = { | ||
var _b; | ||
Object.defineProperties(result, (_b = {}, | ||
_b[name_1] = { | ||
get: function () { return originalGetters["" + prefix + name_1]; } | ||
}, | ||
_a)); | ||
_b)); | ||
}; | ||
@@ -159,3 +155,3 @@ for (var _i = 0, _a = Object.keys(gettersImpl); _i < _a.length; _i++) { | ||
if (moduleOptions.namespaced) | ||
result[moduleName] = commitFromOptions({}, moduleOptions, originalCommitCall, __spreadArrays(hierarchy, [moduleName])); | ||
result[moduleName] = commitFromOptions({}, moduleOptions, originalCommitCall, __spreadArray(__spreadArray([], hierarchy), [moduleName])); | ||
else | ||
@@ -208,3 +204,3 @@ commitFromOptions(result, moduleOptions, originalCommitCall, hierarchy); | ||
if (moduleOptions.namespaced) | ||
result[moduleName] = dispatchFromOptions({}, moduleOptions, originalDispatchCall, __spreadArrays(hierarchy, [moduleName])); | ||
result[moduleName] = dispatchFromOptions({}, moduleOptions, originalDispatchCall, __spreadArray(__spreadArray([], hierarchy), [moduleName])); | ||
else | ||
@@ -211,0 +207,0 @@ dispatchFromOptions(result, moduleOptions, originalDispatchCall, hierarchy); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vuex")):"function"==typeof define&&define.amd?define(["exports","vuex"],t):t((e=e||self).DirectVuex={},e.Vuex)}(this,(function(e,t){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var r=this&&this.__spreadArrays||function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var u=arguments[t],i=0,a=u.length;i<a;i++,o++)n[o]=u[i];return n};function n(e){var r=new t.Store(e),n={get state(){return r.state},getters:x(e,r.getters),commit:j(e,r.commit),dispatch:b(e,r.dispatch),original:r};return r.direct=n,{store:n,rootGetterContext:function(t){var r=t[0],n=t[1];return W([r,n,r,n],e,e)},moduleGetterContext:function(t,r){return W(t,r,e)},rootActionContext:function(t){return D(t,e,e)},moduleActionContext:function(t,r){return D(t,r,e)}}}function o(e,t){return W([e[0],e[1],void 0,void 0],t)}function u(e,t){return D(e,t)}function i(e){return e}function a(){return function(e){return e}}function c(){return function(e){return e}}function s(){return function(e){return e}}function f(e){return e}var d=p(i,"createModule","defineModule"),l=p(a,"createModules","defineModules"),g=p(c,"createGetters","defineGetters"),v=p(s,"createMutations","defineMutations"),m=p(f,"createActions","defineActions");function p(e,t,r){return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return console.warn("Function '"+t+"' is obsolete, please use '"+r+"'."),e.apply(void 0,n)}}var M={createDirectStore:n,defineModule:i,defineModules:a,defineGetters:c,defineMutations:s,defineActions:f,localGetterContext:o,localActionContext:u,createModule:d,createModules:l,createGetters:g,createMutations:v,createActions:m},h=new WeakMap;function x(e,t){var n=h.get(t);return n||(n=function e(t,n,o,u){void 0===u&&(u=[]);n.getters&&function(e,t,r,n){for(var o=n&&0!==n.length?n.join("/")+"/":"",u=function(t){var n;Object.defineProperties(e,((n={})[t]={get:function(){return r[""+o+t]}},n))},i=0,a=Object.keys(t);i<a.length;i++){var c=a[i];u(c)}}(t,n.getters,o,u);if(n.modules)for(var i=0,a=Object.keys(n.modules);i<a.length;i++){var c=a[i],s=n.modules[c];s.namespaced?t[c]=e({},s,o,r(u,[c])):e(t,s,o,u)}return t}({},e,t),h.set(t,n)),n}var y=new WeakMap;function j(e,t){var r=y.get(t);return r||(r=G({},e,t),y.set(t,r)),r}var k=new WeakMap;function G(e,t,n,o){if(void 0===o&&(o=[]),t.mutations&&function(e,t,r,n){for(var o=n&&0!==n.length?n.join("/")+"/":"",u=function(t){e[t]=function(e){return r(""+o+t,e)}},i=0,a=Object.keys(t);i<a.length;i++){var c=a[i];u(c)}}(e,t.mutations,n,o),t.modules)for(var u=0,i=Object.keys(t.modules);u<i.length;u++){var a=i[u],c=t.modules[a];c.namespaced?e[a]=G({},c,n,r(o,[a])):G(e,c,n,o)}return e}var A=new WeakMap;function b(e,t){var r=A.get(t);return r||(r=O({},e,t),A.set(t,r)),r}var w=new WeakMap;function O(e,t,n,o){if(void 0===o&&(o=[]),t.actions&&function(e,t,r,n){for(var o=n&&0!==n.length?n.join("/")+"/":"",u=function(t){e[t]=function(e){return r(""+o+t,e)}},i=0,a=Object.keys(t);i<a.length;i++){var c=a[i];u(c)}}(e,t.actions,n,o),t.modules)for(var u=0,i=Object.keys(t.modules);u<i.length;u++){var a=i[u],c=t.modules[a];c.namespaced?e[a]=O({},c,n,r(o,[a])):O(e,c,n,o)}return e}var C=new WeakMap;function W(e,t,r){var n=e[0],o=e[1],u=e[2],i=e[3],a=S.get(n);return a||(a=r?{get rootState(){return u},get rootGetters(){return x(r,i)},get state(){return n},get getters(){return x(t,o)}}:{get state(){return n},get getters(){return x(t,o)}},n&&C.set(n,a)),a}var S=new WeakMap;function D(e,t,r){var n=S.get(e.state);return n||(n=r?{get rootState(){return e.rootState},get rootGetters(){return x(r,e.rootGetters)},get rootCommit(){return function(e,t){var r=k.get(t);if(!r){r=G({},e,(function(e,r){return t(e,r,{root:!0})})),k.set(t,r)}return r}(r,e.commit)},get rootDispatch(){return function(e,t){var r=w.get(t);if(!r){r=O({},e,(function(e,r){return t(e,r,{root:!0})})),w.set(t,r)}return r}(r,e.dispatch)},get state(){return e.state},get getters(){return x(t,e.getters)},get commit(){return j(t,e.commit)},get dispatch(){return b(t,e.dispatch)}}:{get state(){return e.state},get getters(){return x(t,e.getters)},get commit(){return j(t,e.commit)},get dispatch(){return b(t,e.dispatch)}},e.state&&S.set(e.state,n)),n}e.createActions=m,e.createDirectStore=n,e.createGetters=g,e.createModule=d,e.createModules=l,e.createMutations=v,e.default=M,e.defineActions=f,e.defineGetters=c,e.defineModule=i,e.defineModules=a,e.defineMutations=s,e.localActionContext=u,e.localGetterContext=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
undefined |
{ | ||
"name": "direct-vuex", | ||
"version": "0.12.1", | ||
"version": "1.0.0-rc3", | ||
"description": "Use and implement your Vuex store with TypeScript types. Compatible with the Vue 3 composition API.", | ||
@@ -14,3 +14,4 @@ "author": "Paleo", | ||
"scripts": { | ||
"prepublishOnly": "npm run build && npm run test", | ||
"prepublishOnly": "npm run test", | ||
"prepare": "npm run build", | ||
"clear": "rimraf 'build/compiled-*/*'", | ||
@@ -27,16 +28,16 @@ "tsc": "tsc", | ||
"peerDependencies": { | ||
"vue": "*", | ||
"vuex": "*" | ||
"vue": "3", | ||
"vuex": "4" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^25.2.3", | ||
"jest": "^26.0.1", | ||
"@types/jest": "^26.0.20", | ||
"jest": "^26.6.3", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.15.0", | ||
"terser": "^4.7.0", | ||
"ts-jest": "^26.1.0", | ||
"tslint": "^6.1.2", | ||
"typescript": "^3.9.5", | ||
"vue": "^2.6.11", | ||
"vuex": "^3.4.0" | ||
"rollup": "^2.39.1", | ||
"terser": "^5.6.0", | ||
"ts-jest": "^26.5.2", | ||
"tslint": "^6.1.3", | ||
"typescript": "^4.2.2", | ||
"vue": "^3.0.5", | ||
"vuex": "^4.0.0" | ||
}, | ||
@@ -43,0 +44,0 @@ "repository": { |
@@ -13,3 +13,3 @@ # direct-vuex | ||
First, add `direct-vuex` to a Vue 2 application: | ||
First, add `direct-vuex` to a **Vue 2** application: | ||
@@ -20,3 +20,3 @@ ```sh | ||
Or in a Vue 3 application: | ||
Or, in a **Vue 3** application: | ||
@@ -171,5 +171,5 @@ ```sh | ||
} | ||
} | ||
}, | ||
getters: { | ||
p1OrDefault(...args) { | ||
p1OrDefault(...args): string { | ||
const { state, getters, rootState, rootGetters } = mod1GetterContext(args) | ||
@@ -176,0 +176,0 @@ // Here, 'getters', 'state', 'rootGetters' and 'rootState' are typed. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
53471
793