This commit is contained in:
2022-07-21 03:28:35 +00:00
parent d7c883d6df
commit 51b34b0e1d
30103 changed files with 4152204 additions and 23 deletions
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2017 katashin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+75
View File
@@ -0,0 +1,75 @@
# vuex-class
[![vuex-class Dev Token](https://badge.devtoken.rocks/vuex-class)](https://devtoken.rocks/package/vuex-class)
Binding helpers for Vuex and vue-class-component
## Dependencies
- [Vue](https://github.com/vuejs/vue)
- [Vuex](https://github.com/vuejs/vuex)
- [vue-class-component](https://github.com/vuejs/vue-class-component)
## Installation
```bash
$ npm install --save vuex-class
# or
$ yarn add vuex-class
```
## Example
```js
import Vue from 'vue'
import Component from 'vue-class-component'
import {
State,
Getter,
Action,
Mutation,
namespace
} from 'vuex-class'
const someModule = namespace('path/to/module')
@Component
export class MyComp extends Vue {
@State('foo') stateFoo
@State(state => state.bar) stateBar
@Getter('foo') getterFoo
@Action('foo') actionFoo
@Mutation('foo') mutationFoo
@someModule.Getter('foo') moduleGetterFoo
// If the argument is omitted, use the property name
// for each state/getter/action/mutation type
@State foo
@Getter bar
@Action baz
@Mutation qux
created () {
this.stateFoo // -> store.state.foo
this.stateBar // -> store.state.bar
this.getterFoo // -> store.getters.foo
this.actionFoo({ value: true }) // -> store.dispatch('foo', { value: true })
this.mutationFoo({ value: true }) // -> store.commit('foo', { value: true })
this.moduleGetterFoo // -> store.getters['path/to/module/foo']
}
}
```
## Issue Reporting Guideline
### Questions
For general usage question which is not related to vuex-class should be posted to [StackOverflow](https://stackoverflow.com/) or other Q&A forum. Such questions will be closed without an answer.
### Bug Reports
Please make sure to provide minimal and self-contained reproduction when you report a bug. Otherwise the issue will be closed immediately.
## License
MIT
+95
View File
@@ -0,0 +1,95 @@
/*!
* vuex-class v0.3.2
* https://github.com/ktsn/vuex-class
*
* @license
* Copyright (c) 2017 katashin
* Released under the MIT license
* https://github.com/ktsn/vuex-class/blob/master/LICENSE
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vueClassComponent = require('vue-class-component');
var vuex = require('vuex');
var State = createBindingHelper('computed', vuex.mapState);
var Getter = createBindingHelper('computed', vuex.mapGetters);
var Action = createBindingHelper('methods', vuex.mapActions);
var Mutation = createBindingHelper('methods', vuex.mapMutations);
function namespace(namespace, helper) {
function createNamespacedHelper(helper) {
function namespacedHelper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return helper(key, { namespace: namespace })(proto, key);
}
var type = a;
var options = merge(b || {}, { namespace: namespace });
return helper(type, options);
}
return namespacedHelper;
}
if (helper) {
console.warn('[vuex-class] passing the 2nd argument to `namespace` function is deprecated. pass only namespace string instead.');
return createNamespacedHelper(helper);
}
return {
State: createNamespacedHelper(State),
Getter: createNamespacedHelper(Getter),
Mutation: createNamespacedHelper(Mutation),
Action: createNamespacedHelper(Action)
};
}
function createBindingHelper(bindTo, mapFn) {
function makeDecorator(map, namespace) {
return vueClassComponent.createDecorator(function (componentOptions, key) {
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {};
}
var mapObject = (_a = {}, _a[key] = map, _a);
componentOptions[bindTo][key] = namespace !== undefined
? mapFn(namespace, mapObject)[key]
: mapFn(mapObject)[key];
var _a;
});
}
function helper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return makeDecorator(key, undefined)(proto, key);
}
var namespace = extractNamespace(b);
var type = a;
return makeDecorator(type, namespace);
}
return helper;
}
function extractNamespace(options) {
var n = options && options.namespace;
if (typeof n !== 'string') {
return undefined;
}
if (n[n.length - 1] !== '/') {
return n + '/';
}
return n;
}
function merge(a, b) {
var res = {};
[a, b].forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
res[key] = obj[key];
});
});
return res;
}
exports.State = State;
exports.Getter = Getter;
exports.Action = Action;
exports.Mutation = Mutation;
exports.namespace = namespace;
+98
View File
@@ -0,0 +1,98 @@
/*!
* vuex-class v0.3.2
* https://github.com/ktsn/vuex-class
*
* @license
* Copyright (c) 2017 katashin
* Released under the MIT license
* https://github.com/ktsn/vuex-class/blob/master/LICENSE
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-class-component'), require('vuex')) :
typeof define === 'function' && define.amd ? define(['exports', 'vue-class-component', 'vuex'], factory) :
(factory((global.VuexClass = {}),global.VueClassComponent,global.Vuex));
}(this, (function (exports,vueClassComponent,vuex) { 'use strict';
var State = createBindingHelper('computed', vuex.mapState);
var Getter = createBindingHelper('computed', vuex.mapGetters);
var Action = createBindingHelper('methods', vuex.mapActions);
var Mutation = createBindingHelper('methods', vuex.mapMutations);
function namespace(namespace, helper) {
function createNamespacedHelper(helper) {
function namespacedHelper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return helper(key, { namespace: namespace })(proto, key);
}
var type = a;
var options = merge(b || {}, { namespace: namespace });
return helper(type, options);
}
return namespacedHelper;
}
if (helper) {
console.warn('[vuex-class] passing the 2nd argument to `namespace` function is deprecated. pass only namespace string instead.');
return createNamespacedHelper(helper);
}
return {
State: createNamespacedHelper(State),
Getter: createNamespacedHelper(Getter),
Mutation: createNamespacedHelper(Mutation),
Action: createNamespacedHelper(Action)
};
}
function createBindingHelper(bindTo, mapFn) {
function makeDecorator(map, namespace) {
return vueClassComponent.createDecorator(function (componentOptions, key) {
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {};
}
var mapObject = (_a = {}, _a[key] = map, _a);
componentOptions[bindTo][key] = namespace !== undefined
? mapFn(namespace, mapObject)[key]
: mapFn(mapObject)[key];
var _a;
});
}
function helper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return makeDecorator(key, undefined)(proto, key);
}
var namespace = extractNamespace(b);
var type = a;
return makeDecorator(type, namespace);
}
return helper;
}
function extractNamespace(options) {
var n = options && options.namespace;
if (typeof n !== 'string') {
return undefined;
}
if (n[n.length - 1] !== '/') {
return n + '/';
}
return n;
}
function merge(a, b) {
var res = {};
[a, b].forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
res[key] = obj[key];
});
});
return res;
}
exports.State = State;
exports.Getter = Getter;
exports.Action = Action;
exports.Mutation = Mutation;
exports.namespace = namespace;
Object.defineProperty(exports, '__esModule', { value: true });
})));
+10
View File
@@ -0,0 +1,10 @@
/*!
* vuex-class v0.3.2
* https://github.com/ktsn/vuex-class
*
* @license
* Copyright (c) 2017 katashin
* Released under the MIT license
* https://github.com/ktsn/vuex-class/blob/master/LICENSE
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-class-component"),require("vuex")):"function"==typeof define&&define.amd?define(["exports","vue-class-component","vuex"],t):t(e.VuexClass={},e.VueClassComponent,e.Vuex)}(this,function(e,t,n){"use strict";var o=i("computed",n.mapState),r=i("computed",n.mapGetters),a=i("methods",n.mapActions),u=i("methods",n.mapMutations);function i(u,i){function r(r,a){return t.createDecorator(function(e,t){e[u]||(e[u]={});var n,o=((n={})[t]=r,n);e[u][t]=void 0!==a?i(a,o)[t]:i(o)[t]})}return function(e,t){if("string"==typeof t){var n=t,o=e;return r(n,void 0)(o,n)}return r(e,function(e){var t=e&&e.namespace;if("string"==typeof t)return"/"!==t[t.length-1]?t+"/":t}(t))}}e.State=o,e.Getter=r,e.Action=a,e.Mutation=u,e.namespace=function(c,e){function t(i){return function(e,t){if("string"==typeof t){var n=t,o=e;return i(n,{namespace:c})(o,n)}var r,a=e,u=(r={},[t||{},{namespace:c}].forEach(function(t){Object.keys(t).forEach(function(e){r[e]=t[e]})}),r);return i(a,u)}}return e?(console.warn("[vuex-class] passing the 2nd argument to `namespace` function is deprecated. pass only namespace string instead."),t(e)):{State:t(o),Getter:t(r),Mutation:t(u),Action:t(a)}},Object.defineProperty(e,"__esModule",{value:!0})});
+27
View File
@@ -0,0 +1,27 @@
import Vue from 'vue';
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex';
export declare type VuexDecorator = <V extends Vue>(proto: V, key: string) => void;
export declare type StateTransformer = (state: any, getters: any) => any;
export declare type MapHelper = typeof mapState | typeof mapGetters | typeof mapActions | typeof mapMutations;
export interface BindingOptions {
namespace?: string;
}
export interface BindingHelper {
<V extends Vue>(proto: V, key: string): void;
(type: string, options?: BindingOptions): VuexDecorator;
}
export interface StateBindingHelper extends BindingHelper {
(type: StateTransformer, options?: BindingOptions): VuexDecorator;
}
export interface BindingHelpers {
State: StateBindingHelper;
Getter: BindingHelper;
Mutation: BindingHelper;
Action: BindingHelper;
}
export declare const State: StateBindingHelper;
export declare const Getter: BindingHelper;
export declare const Action: BindingHelper;
export declare const Mutation: BindingHelper;
export declare function namespace(namespace: string): BindingHelpers;
export declare function namespace<T extends BindingHelper>(namespace: string, helper: T): T;
+75
View File
@@ -0,0 +1,75 @@
import { createDecorator } from 'vue-class-component';
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex';
export var State = createBindingHelper('computed', mapState);
export var Getter = createBindingHelper('computed', mapGetters);
export var Action = createBindingHelper('methods', mapActions);
export var Mutation = createBindingHelper('methods', mapMutations);
export function namespace(namespace, helper) {
function createNamespacedHelper(helper) {
function namespacedHelper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return helper(key, { namespace: namespace })(proto, key);
}
var type = a;
var options = merge(b || {}, { namespace: namespace });
return helper(type, options);
}
return namespacedHelper;
}
if (helper) {
console.warn('[vuex-class] passing the 2nd argument to `namespace` function is deprecated. pass only namespace string instead.');
return createNamespacedHelper(helper);
}
return {
State: createNamespacedHelper(State),
Getter: createNamespacedHelper(Getter),
Mutation: createNamespacedHelper(Mutation),
Action: createNamespacedHelper(Action)
};
}
function createBindingHelper(bindTo, mapFn) {
function makeDecorator(map, namespace) {
return createDecorator(function (componentOptions, key) {
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {};
}
var mapObject = (_a = {}, _a[key] = map, _a);
componentOptions[bindTo][key] = namespace !== undefined
? mapFn(namespace, mapObject)[key]
: mapFn(mapObject)[key];
var _a;
});
}
function helper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return makeDecorator(key, undefined)(proto, key);
}
var namespace = extractNamespace(b);
var type = a;
return makeDecorator(type, namespace);
}
return helper;
}
function extractNamespace(options) {
var n = options && options.namespace;
if (typeof n !== 'string') {
return undefined;
}
if (n[n.length - 1] !== '/') {
return n + '/';
}
return n;
}
function merge(a, b) {
var res = {};
[a, b].forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
res[key] = obj[key];
});
});
return res;
}
+1
View File
@@ -0,0 +1 @@
export { State, Getter, Action, Mutation, namespace } from './bindings';
+1
View File
@@ -0,0 +1 @@
export { State, Getter, Action, Mutation, namespace } from './bindings';
+101
View File
@@ -0,0 +1,101 @@
{
"_args": [
[
"vuex-class@0.3.2",
"/home/node/nuxt"
]
],
"_from": "vuex-class@0.3.2",
"_id": "vuex-class@0.3.2",
"_inBundle": false,
"_integrity": "sha512-m0w7/FMsNcwJgunJeM+wcNaHzK2KX1K1rw2WUQf7Q16ndXHo7pflRyOV/E8795JO/7fstyjH3EgqBI4h4n4qXQ==",
"_location": "/vuex-class",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "vuex-class@0.3.2",
"name": "vuex-class",
"escapedName": "vuex-class",
"rawSpec": "0.3.2",
"saveSpec": null,
"fetchSpec": "0.3.2"
},
"_requiredBy": [
"/nuxt-property-decorator"
],
"_resolved": "https://registry.npmjs.org/vuex-class/-/vuex-class-0.3.2.tgz",
"_spec": "0.3.2",
"_where": "/home/node/nuxt",
"author": {
"name": "katashin"
},
"bugs": {
"url": "https://github.com/ktsn/vuex-class/issues"
},
"description": "Binding helpers for Vuex and vue-class-component",
"devDependencies": {
"@types/mocha": "^5.2.0",
"@types/power-assert": "1.5.0",
"@types/sinon": "^4.3.3",
"es6-promise": "^4.2.4",
"glob": "^7.1.2",
"json-loader": "^0.5.7",
"npm-run-all": "^4.1.3",
"power-assert": "^1.5.0",
"rollup": "^0.58.2",
"rollup-plugin-replace": "^2.0.0",
"sinon": "^5.0.7",
"testem": "^2.4.0",
"ts-loader": "^4.3.0",
"tslint": "^5.10.0",
"tslint-config-ktsn": "^2.1.0",
"typescript": "^2.8.3",
"uglify-js": "^3.3.25",
"vue": "^2.5.16",
"vue-class-component": "^6.2.0",
"vuex": "^3.0.1",
"webpack": "^4.8.3",
"webpack-cli": "^2.1.3",
"webpack-espower-loader": "^2.0.0"
},
"files": [
"dist",
"lib"
],
"homepage": "https://github.com/ktsn/vuex-class",
"keywords": [
"vue",
"vuex",
"bindings"
],
"license": "MIT",
"main": "dist/vuex-class.cjs.js",
"module": "lib/index.js",
"name": "vuex-class",
"peerDependencies": {
"vue": "^2.5.0",
"vuex": "^3.0.0",
"vue-class-component": "^6.0.0 || ^7.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ktsn/vuex-class.git"
},
"scripts": {
"build": "run-s build:ts build:cjs build:dev build:prod",
"build:cjs": "rollup -c scripts/rollup.config.js --environment BUILD:commonjs",
"build:dev": "rollup -c scripts/rollup.config.js --environment BUILD:development",
"build:prod": "rollup -c scripts/rollup.config.js --environment BUILD:production | uglifyjs -mc warnings=false --comments -o dist/vuex-class.min.js",
"build:ts": "tsc -p src",
"clean": "rm -rf lib dist .tmp",
"dev": "run-p watch:test testem",
"lint": "tslint \"src/**/*.ts\" && tslint \"test/**/*.ts\"",
"prepublishOnly": "run-s lint test clean build",
"test": "webpack --config scripts/webpack.config.test.js && testem ci --launch PhantomJS",
"testem": "testem",
"watch:test": "webpack --watch --config scripts/webpack.config.test.js"
},
"typings": "lib/index.d.ts",
"version": "0.3.2"
}