vue-act-master 0.16.0 โ†’ 2.0.1

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.
package/README.md CHANGED
@@ -15,9 +15,6 @@ The easiest library to create a flexible application architecture.
15
15
 
16
16
  ## ๐Ÿ“— [Documentation](https://avil13.github.io/vue-act-master/)
17
17
 
18
-
19
- ## ๐Ÿ—บ [Example project structure](https://github.com/avil13/vue-act-master/blob/master/packages/example/README.md)
20
-
21
18
  ## ๐Ÿงช [Test writing with "ActTest"](https://github.com/avil13/vue-act-master/blob/master/packages/act-master/src/test-utils/README.md)
22
19
 
23
20
 
@@ -42,7 +39,7 @@ import App from './App.vue';
42
39
  import { VueActMaster } from 'vue-act-master';
43
40
 
44
41
  // Actions array
45
- import { actions } from '../you/actions/path';
42
+ import { actions } from '../act/actions';
46
43
 
47
44
  Vue.use(VueActMaster, {
48
45
  actions,
@@ -55,7 +52,7 @@ new Vue({
55
52
  ```
56
53
 
57
54
  ```ts
58
- // ../you/actions/path
55
+ // ../act/actions
59
56
  export const actions: ActMasterAction[] = [
60
57
  new GetDataAction(),
61
58
  ];
@@ -0,0 +1 @@
1
+ (function(c,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(c=typeof globalThis<"u"?globalThis:c||self,u(c["vue-act-master"]={}))})(this,function(c){"use strict";var W=Object.defineProperty;var x=(c,u,b)=>u in c?W(c,u,{enumerable:!0,configurable:!0,writable:!0,value:b}):c[u]=b;var O=(c,u,b)=>(x(c,typeof u!="symbol"?u+"":u,b),b);var u=Object.defineProperty,b=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,o=(e,t,s)=>(b(e,typeof t!="symbol"?t+"":t,s),s);class d{constructor(t,s){if(o(this,"reason",""),o(this,"data"),typeof t=="string"){this.reason=t,this.data=s;return}if(t&&typeof t=="object")return Object.assign(t,{_name:this._name,reason:t.message||""})}static get _name(){return"__CancelledAct__"}get _name(){return d._name}static is(t){return!t||typeof t!="object"?!1:t._name===d._name}valueOf(){return null}toString(){return this.reason}}class A extends Error{constructor(t){super(`Can't find "${t}" action`),this.eventName=t}}class D extends Error{constructor(t){super(`Action "${t}" already existing`),this.eventName=t}}class v extends Error{constructor(t){super(`"${t}" already exists in DI`),this.key=t}}class $ extends Error{constructor(){super(`"di" can't be array`)}}const S="2.0.1";function k(e){return function(t,s){t._DI_MAP_||(t._DI_MAP_={}),t._DI_MAP_[s]=e}}function j(){return(e,t)=>{Object.defineProperty(e,"useEmit",{value:function(s){this[t]=s}})}}const y=class{constructor(e={}){if(o(this,"version",S),o(this,"_actions",new Map),o(this,"_watchers",new Map),o(this,"_listeners",new Map),o(this,"_inProgressWatchers",new Map),o(this,"_subsMap",new Map),o(this,"_lastUnsubscribe",()=>!1),o(this,"_DIContainer",{}),o(this,"_singlePromisesStore",new Map),o(this,"config",{errorOnReplaceDI:!1,autoUnsubscribeCallback:void 0,errorHandlerEventName:void 0}),o(this,"exec",async(i,...h)=>{if(this.setProgress(i,!0),this._singlePromisesStore.has(i)){const f=this._singlePromisesStore.get(i);if(f)return f}const _=this.emit(i,...h).then(f=>(this.setProgress(i,!1),f)).then(f=>(this._singlePromisesStore.has(i)&&this._singlePromisesStore.delete(i),f)).catch(f=>{if(this.setProgress(i,!1),f instanceof A)throw f;const P=this.getActionOrNull(i);if(P!=null&&P.errorHandlerEventName&&P.errorHandlerEventName!==i)return this.emit(P.errorHandlerEventName,f),new d(f);if(this.config.errorHandlerEventName&&this.config.errorHandlerEventName!==i)return this.emit(this.config.errorHandlerEventName,f),Promise.resolve(null);throw f}),m=this.getActionOrNull(i);return m&&m.isSingleExec&&this._singlePromisesStore.set(i,_),_}),o(this,"subscribe",(i,h,_)=>{this._listeners.set(i,[...this._listeners.get(i)||[],h]);const m=()=>this.unsubscribe(i,h);return this._lastUnsubscribe=m,this.config.autoUnsubscribeCallback&&this.config.autoUnsubscribeCallback({context:_,listener:h,eventName:i}),_&&this.subsList.add(_),m}),o(this,"once",(i,h)=>{const _=this.subscribe(i,(...m)=>{_(),h(...m)});return _}),o(this,"on",(i,h,_)=>this.subscribe(i,h,_)),y.instance)return y.instance;const{actions:t,di:s,errorOnReplaceDI:r,autoUnsubscribeCallback:n,errorHandlerEventName:l}=e;if(t&&this.addActions(t),typeof n=="function"&&(this.config.autoUnsubscribeCallback=n),typeof s=="object"&&s){if(Array.isArray(s))throw new $;for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&this.setDI(i,s[i])}typeof r=="boolean"&&(this.config.errorOnReplaceDI=r),typeof l=="string"&&(this.config.errorHandlerEventName=l),y.instance=this}static getInstance(){if(!y.instance)throw new Error("ActMaster not initialized");return y.instance}addActions(e){Array.isArray(e)&&e.forEach(t=>{this.addAction(t)})}addAction(e){const t=e.name;if(this._actions.has(t))throw new D(t);if(e.useEmit){const s=(r,...n)=>this.emit(r,...n);e.useEmit(s)}return this._actions.set(t,e),this.emitDIProps(e),e.watch&&e.watch.forEach(s=>{const r=this._watchers.get(s)||[];r.push(t),this._watchers.set(s,r)}),this}removeAction(e){if(!this._actions.has(e))throw new A(e);this._actions.delete(e)}clearActions(){this._actions.clear()}clearListeners(){for(const e in this._listeners)this._listeners.has(e)&&this._listeners.delete(e)}async emit(e,...t){const s=this.getActionOrNull(e);if(s===null)throw new A(e);if(s.validateInput){const n=await s.validateInput(...t);if(n!==!0)return this.config.errorHandlerEventName&&this.emit(this.config.errorHandlerEventName,n),n}const r=await s.exec(...t);if(r instanceof d||d.is(r))return r;if(this.notifyListeners(e,r),this._watchers.has(e))for(const n of this._watchers.get(e)||[])this.emit(n,r);return r}notifyListeners(e,t){const s=this._listeners.get(e);s&&s.forEach(r=>{r(t)})}unsubscribe(e,t){const s=this._listeners.get(e);if(!s)return this._subsMap.set(e,[]),!1;const r=s.indexOf(t);return r>-1&&s.splice(r,1),this._listeners.set(e,s),r>-1}off(e,t){return this.unsubscribe(e,t)}inProgress(e,t){if(Array.isArray(e)){e.forEach(n=>this._inProgressWatchers.set(n,t));const r=()=>{e.forEach(n=>{this._inProgressWatchers.delete(n)})};return this._lastUnsubscribe=r,r}this._inProgressWatchers.set(e,t);const s=()=>this._inProgressWatchers.delete(e);return this._lastUnsubscribe=s,s}setProgress(e,t){this._inProgressWatchers.has(e)&&this._inProgressWatchers.get(e)(t)}get subsList(){return{add:(e,...t)=>{t.length||t.push(this._lastUnsubscribe);const s=this._subsMap.get(e)||[];s.push(...t),this._subsMap.set(e,s)},clear:e=>{(this._subsMap.get(e)||[]).forEach(t=>t()),this._subsMap.delete(e)}}}clearDI(){this._DIContainer={}}setDI(e,t){if(this.config.errorOnReplaceDI&&this._DIContainer[e])throw new v(e);return this._DIContainer[e]=t,this.freshEmitDI(),this}freshEmitDI(){let e;Object.keys(this._actions).forEach(t=>{e=this._actions.get(t),e&&this.emitDIProps(e)})}emitDIProps(e){e._DI_CONTAINER_||Object.defineProperty(e,"_DI_CONTAINER_",{get:()=>this._DIContainer,enumerable:!1}),e._DI_MAP_&&Object.keys(e._DI_MAP_).forEach(t=>{var s;if(e[t])return;const r=(s=e._DI_MAP_)==null?void 0:s[t];r&&Object.defineProperty(e,t,{get(){return this._DI_CONTAINER_[r]},enumerable:!0})}),e.useDI&&e.useDI(this._DIContainer)}getActionOrNull(e){return this._actions.get(e)||null}};let g=y;o(g,"instance");const a=class{constructor(){}static getInstance(e={}){return a.resetAll(),a.removeSingleton(),a.$act=new g(e),a.$act}static resetAll(){a.$act&&(a.$act.clearActions(),a.$act.clearListeners(),a.$act.clearDI()),a._lastResult=void 0}static removeSingleton(){g.instance=void 0,a._lastResult=void 0}static addActions(e){a.$act.addActions(e)}static exec(e,...t){return a.$act.exec(e,...t).then(s=>(a._lastResult=s,s)).catch(s=>{throw a._lastResult=s,s})}static subscribe(e,t,s){return a.$act.subscribe(e,t,s)}static entityCount(e){if(e==="di")return Object.keys(a.$act._DIContainer).length;if(e==="actions")return a.$act._actions.size;const t={watchers:"_watchers",listeners:"_listeners"}[e];let s=0;return a.$act[t].forEach(r=>{s+=r.length}),s}static getLastResult(){return a._lastResult}static makeActionStub(e){return{name:`Act_${Math.random()}`,exec:()=>null,...e}}};let p=a;o(p,"$act"),o(p,"_lastResult"),I.init=e=>new g(e);const R=(e,t,s)=>{const r=I().subscribe(e,t);return s&&(typeof s=="function"?s(r):I().subsList.add(s,r)),r},M=e=>I().subsList.clear(e);I.subListClear=M;function I(){const e=g.getInstance();if(!e)throw new Error('Instance call before initialization. Make a "new ActMaster()" first');return e}const C=e=>{if(typeof e!="function"||!e.name)throw new Error(`Pass not valid function: "${e}"`);return{name:e.name,exec:e}},H=C;function N(e){return(t,s,r)=>{const n=typeof t=="function"?t:t.constructor;n.__decorators__||(n.__decorators__=[]),typeof r!="number"&&(r=void 0),n.__decorators__.push(l=>e(l,s,r))}}function U(e,t,s=null){return N((r,n)=>{const l={created(){this.$act.subscribe(e,i=>{const h=L(i,t,s);typeof this[n]=="function"?this[n](h):this[n]=h},this)}};r.mixins?r.mixins=[...r.mixins,l]:r.mixins=[l]})}function L(e,t,s){if(e===void 0)return s;if(typeof t=="function")return t(e);let r=e;if(t){const n=(t||"").split(".");let l,i=0;for(i=0;i<n.length&&r;i++)l=n[i],r=r[l]}return r===void 0?s:r}function T(e){return N((t,s)=>{const r={created(){const n=this.$act.inProgress(e,l=>{this[s]=l});this.$once("hook:beforeDestroy",()=>{n(e)})}};t.mixins?t.mixins=[...t.mixins,r]:t.mixins=[r]})}const E=class{static install(t,s){var n;debugger;const r=new g({autoUnsubscribeCallback({context:l,eventName:i,listener:h}){l&&typeof l=="function"?l(function(){r.unsubscribe(i,h)}):l&&typeof l.$once=="function"&&l.$once("hook:beforeDestroy",()=>{r.unsubscribe(i,h)})},...s});E.instance=r,(n=t.config)!=null&&n.globalProperties&&!t.config.globalProperties.$act?(t.config.globalProperties.$act=r,t.provide("$act",r)):Object.prototype.hasOwnProperty.call(t,"$act")||(t.act=r,t.prototype.$act=r)}install(t,s){E.install(t,s)}};let w=E;O(w,"instance",null),c.ActInProgress=T,c.ActMaster=g,c.ActSubscribe=U,c.ActTest=p,c.ActinonAlreadyExistingError=D,c.CancelledAct=d,c.Emit=j,c.InvalidDITypeError=$,c.KeyAlreadyExistsInDIError=v,c.NotFoundActionError=A,c.UseDI=k,c.VueActMaster=w,c.act=I,c.actSubscribe=R,c.fn2act=H,c.functionToAction=C,c.subListClear=M,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "vue-act-master",
3
- "version": "0.16.0",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "author": "avil13",
6
- "main": "dist/index.common.js",
7
- "module": "dist/index.esm.js",
8
- "browser": "dist/index.umd.js",
9
- "typings": "dist/vue-act-master/src/index.d.ts",
6
+ "main": "dist/vue-act-master.umd.cjs",
7
+ "module": "dist/vue-act-master.js",
8
+ "typings": "dist/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "require": "./dist/vue-act-master.umd.cjs",
13
+ "import": "./dist/vue-act-master.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
10
17
  "files": [
11
18
  "README.md",
12
19
  "dist",
@@ -22,14 +29,16 @@
22
29
  "business logic"
23
30
  ],
24
31
  "scripts": {
25
- "build": "rm -rf ./dist && rollup -c",
32
+ "build": "rm -rf ./dist && vite build && tsc -p tsconfig.prod.json",
26
33
  "changelog": "auto-changelog && git add CHANGELOG.md",
34
+ "size": "size-limit",
27
35
  "lint:fix": "eslint --fix --ext .ts .",
36
+ "test": "vitest run",
28
37
  "test:watch": "vitest dev",
29
- "test": "vitest run --coverage",
38
+ "test:coverage": "vitest run --coverage",
30
39
  "type-check:watch": "npm run type-check -- --watch",
31
- "type-check": "tsc -p ./tsconfig.prod.json --noEmit",
32
- "prepublishOnly": "npm run test && npm run build && npm run changelog"
40
+ "type-check": "tsc -p ./tsconfig.json --noEmit",
41
+ "prepublishOnly": "yarn test && yarn run build"
33
42
  },
34
43
  "husky": {
35
44
  "hooks": {
@@ -43,21 +52,17 @@
43
52
  },
44
53
  "license": "MIT",
45
54
  "dependencies": {
46
- "act-master": "^1.11.*"
55
+ "act-master": "^2.0.1"
56
+ },
57
+ "peerDependencies": {
58
+ "act-master": "^2.0.1"
47
59
  },
48
60
  "devDependencies": {
49
- "@types/node": "^16.10.1",
50
- "@typescript-eslint/eslint-plugin": "^4.31.2",
51
- "auto-changelog": "^2.3.0",
52
- "eslint": "^7.32.0",
53
- "eslint-config-prettier": "^8.3.0",
54
- "eslint-plugin-prettier": "^4.0.0",
55
- "prettier": "^2.4.1",
56
- "rollup": "^2.57.0",
57
- "rollup-plugin-filesize": "^9.1.1",
58
- "rollup-plugin-terser": "^7.0.2",
59
- "rollup-plugin-typescript2": "^0.30.0",
60
- "typescript": "^4.4.3",
61
+ "@babel/types": "^7.22.5",
62
+ "auto-changelog": "^2.4.0",
63
+ "typescript": "^5.0.4",
64
+ "vite": "^4.3.7",
65
+ "vitest": "^0.31.0",
61
66
  "vue": "*"
62
67
  }
63
68
  }
@@ -70,17 +70,6 @@ describe('VueActMaster', () => {
70
70
  const result = await $act.exec(ACTION_NAME);
71
71
  expect(result).toBe(expectRandomValue);
72
72
  });
73
-
74
- it('transform', async () => {
75
- ACTION_NAME = 'ACTION_NAME_EX';
76
-
77
- addTestAction(ACTION_NAME, {
78
- transform: (v: string) => `${v}_SUFFIX`,
79
- });
80
-
81
- const result = await $act.exec(ACTION_NAME);
82
- expect(result).toBe(`${expectRandomValue}_SUFFIX`);
83
- });
84
73
  });
85
74
 
86
75
  describe('Subscriptions', () => {
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ export class VueActMaster {
36
36
  static instance: ActMaster | null = null;
37
37
 
38
38
  static install(vue: any, options?: ActMasterOptions): void {
39
+ debugger;
39
40
  const actMaster = new ActMaster({
40
41
  autoUnsubscribeCallback({ context, eventName, listener }) {
41
42
  if (context && typeof context === 'function') {
@@ -1,128 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var actMaster = require('act-master');
6
-
7
- function createDecorator(factory) {
8
- return (target, key, index) => {
9
- const Ctor = typeof target === 'function'
10
- ? target
11
- : target.constructor;
12
- if (!Ctor.__decorators__) {
13
- Ctor.__decorators__ = [];
14
- }
15
- if (typeof index !== 'number') {
16
- index = undefined;
17
- }
18
- Ctor.__decorators__.push((options) => factory(options, key, index));
19
- };
20
- }
21
-
22
- function ActSubscribe(eventName, pathToData, defaultValue = null) {
23
- return createDecorator((componentOptions, key) => {
24
- const subscribeHook = {
25
- created() {
26
- this.$act.subscribe(eventName, (data) => {
27
- const value = objectPath(data, pathToData, defaultValue);
28
- if (typeof this[key] === 'function') {
29
- this[key](value);
30
- }
31
- else {
32
- this[key] = value;
33
- }
34
- }, this);
35
- },
36
- };
37
- if (componentOptions.mixins) {
38
- componentOptions.mixins = [...componentOptions.mixins, subscribeHook];
39
- }
40
- else {
41
- componentOptions.mixins = [subscribeHook];
42
- }
43
- });
44
- }
45
- function objectPath(obj, path, defaultValue) {
46
- if (obj === undefined) {
47
- return defaultValue;
48
- }
49
- if (typeof path === 'function') {
50
- return path(obj);
51
- }
52
- let value = obj;
53
- if (path) {
54
- const list = (path || '').split('.');
55
- let key;
56
- let i = 0;
57
- for (i = 0; i < list.length && value; i++) {
58
- key = list[i];
59
- value = value[key];
60
- }
61
- }
62
- if (value === undefined) {
63
- return defaultValue;
64
- }
65
- return value;
66
- }
67
-
68
- function ActInProgress(eventName) {
69
- return createDecorator((componentOptions, key) => {
70
- const inProgressHook = {
71
- created() {
72
- const unsubscribe = this.$act.inProgress(eventName, (inProgress) => {
73
- this[key] = inProgress;
74
- });
75
- this.$once('hook:beforeDestroy', () => {
76
- unsubscribe(eventName);
77
- });
78
- },
79
- };
80
- if (componentOptions.mixins) {
81
- componentOptions.mixins = [...componentOptions.mixins, inProgressHook];
82
- }
83
- else {
84
- componentOptions.mixins = [inProgressHook];
85
- }
86
- });
87
- }
88
-
89
- class VueActMaster {
90
- static install(vue, options) {
91
- var _a;
92
- const actMaster$1 = new actMaster.ActMaster(Object.assign({ autoUnsubscribeCallback({ context, eventName, listener }) {
93
- if (context && typeof context === 'function') {
94
- context(function () {
95
- actMaster$1.unsubscribe(eventName, listener);
96
- });
97
- }
98
- else if (context && typeof context.$once === 'function') {
99
- context.$once('hook:beforeDestroy', () => {
100
- actMaster$1.unsubscribe(eventName, listener);
101
- });
102
- }
103
- } }, options));
104
- VueActMaster.instance = actMaster$1;
105
- if (((_a = vue.config) === null || _a === void 0 ? void 0 : _a.globalProperties) && !vue.config.globalProperties.$act) {
106
- vue.config.globalProperties.$act = actMaster$1;
107
- vue.provide('$act', actMaster$1);
108
- }
109
- else if (!Object.prototype.hasOwnProperty.call(vue, '$act')) {
110
- vue.act = actMaster$1;
111
- vue.prototype.$act = actMaster$1;
112
- }
113
- }
114
- install(vue, options) {
115
- VueActMaster.install(vue, options);
116
- }
117
- }
118
- VueActMaster.instance = null;
119
-
120
- exports.ActInProgress = ActInProgress;
121
- exports.ActSubscribe = ActSubscribe;
122
- exports.VueActMaster = VueActMaster;
123
- Object.keys(actMaster).forEach(function (k) {
124
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
125
- enumerable: true,
126
- get: function () { return actMaster[k]; }
127
- });
128
- });
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("act-master");function e(t){return(e,n,o)=>{const r="function"==typeof e?e:e.constructor;r.__decorators__||(r.__decorators__=[]),"number"!=typeof o&&(o=void 0),r.__decorators__.push((e=>t(e,n,o)))}}class n{static install(e,o){var r;const s=new t.ActMaster(Object.assign({autoUnsubscribeCallback({context:t,eventName:e,listener:n}){t&&"function"==typeof t?t((function(){s.unsubscribe(e,n)})):t&&"function"==typeof t.$once&&t.$once("hook:beforeDestroy",(()=>{s.unsubscribe(e,n)}))}},o));n.instance=s,(null===(r=e.config)||void 0===r?void 0:r.globalProperties)&&!e.config.globalProperties.$act?(e.config.globalProperties.$act=s,e.provide("$act",s)):Object.prototype.hasOwnProperty.call(e,"$act")||(e.act=s,e.prototype.$act=s)}install(t,e){n.install(t,e)}}n.instance=null,exports.ActInProgress=function(t){return e(((e,n)=>{const o={created(){const e=this.$act.inProgress(t,(t=>{this[n]=t}));this.$once("hook:beforeDestroy",(()=>{e(t)}))}};e.mixins?e.mixins=[...e.mixins,o]:e.mixins=[o]}))},exports.ActSubscribe=function(t,n,o=null){return e(((e,r)=>{const s={created(){this.$act.subscribe(t,(t=>{const e=function(t,e,n){if(void 0===t)return n;if("function"==typeof e)return e(t);let o=t;if(e){const t=(e||"").split(".");let n,r=0;for(r=0;r<t.length&&o;r++)n=t[r],o=o[n]}if(void 0===o)return n;return o}(t,n,o);"function"==typeof this[r]?this[r](e):this[r]=e}),this)}};e.mixins?e.mixins=[...e.mixins,s]:e.mixins=[s]}))},exports.VueActMaster=n,Object.keys(t).forEach((function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})}));
package/dist/index.esm.js DELETED
@@ -1,117 +0,0 @@
1
- import { ActMaster } from 'act-master';
2
- export * from 'act-master';
3
-
4
- function createDecorator(factory) {
5
- return (target, key, index) => {
6
- const Ctor = typeof target === 'function'
7
- ? target
8
- : target.constructor;
9
- if (!Ctor.__decorators__) {
10
- Ctor.__decorators__ = [];
11
- }
12
- if (typeof index !== 'number') {
13
- index = undefined;
14
- }
15
- Ctor.__decorators__.push((options) => factory(options, key, index));
16
- };
17
- }
18
-
19
- function ActSubscribe(eventName, pathToData, defaultValue = null) {
20
- return createDecorator((componentOptions, key) => {
21
- const subscribeHook = {
22
- created() {
23
- this.$act.subscribe(eventName, (data) => {
24
- const value = objectPath(data, pathToData, defaultValue);
25
- if (typeof this[key] === 'function') {
26
- this[key](value);
27
- }
28
- else {
29
- this[key] = value;
30
- }
31
- }, this);
32
- },
33
- };
34
- if (componentOptions.mixins) {
35
- componentOptions.mixins = [...componentOptions.mixins, subscribeHook];
36
- }
37
- else {
38
- componentOptions.mixins = [subscribeHook];
39
- }
40
- });
41
- }
42
- function objectPath(obj, path, defaultValue) {
43
- if (obj === undefined) {
44
- return defaultValue;
45
- }
46
- if (typeof path === 'function') {
47
- return path(obj);
48
- }
49
- let value = obj;
50
- if (path) {
51
- const list = (path || '').split('.');
52
- let key;
53
- let i = 0;
54
- for (i = 0; i < list.length && value; i++) {
55
- key = list[i];
56
- value = value[key];
57
- }
58
- }
59
- if (value === undefined) {
60
- return defaultValue;
61
- }
62
- return value;
63
- }
64
-
65
- function ActInProgress(eventName) {
66
- return createDecorator((componentOptions, key) => {
67
- const inProgressHook = {
68
- created() {
69
- const unsubscribe = this.$act.inProgress(eventName, (inProgress) => {
70
- this[key] = inProgress;
71
- });
72
- this.$once('hook:beforeDestroy', () => {
73
- unsubscribe(eventName);
74
- });
75
- },
76
- };
77
- if (componentOptions.mixins) {
78
- componentOptions.mixins = [...componentOptions.mixins, inProgressHook];
79
- }
80
- else {
81
- componentOptions.mixins = [inProgressHook];
82
- }
83
- });
84
- }
85
-
86
- class VueActMaster {
87
- static install(vue, options) {
88
- var _a;
89
- const actMaster = new ActMaster(Object.assign({ autoUnsubscribeCallback({ context, eventName, listener }) {
90
- if (context && typeof context === 'function') {
91
- context(function () {
92
- actMaster.unsubscribe(eventName, listener);
93
- });
94
- }
95
- else if (context && typeof context.$once === 'function') {
96
- context.$once('hook:beforeDestroy', () => {
97
- actMaster.unsubscribe(eventName, listener);
98
- });
99
- }
100
- } }, options));
101
- VueActMaster.instance = actMaster;
102
- if (((_a = vue.config) === null || _a === void 0 ? void 0 : _a.globalProperties) && !vue.config.globalProperties.$act) {
103
- vue.config.globalProperties.$act = actMaster;
104
- vue.provide('$act', actMaster);
105
- }
106
- else if (!Object.prototype.hasOwnProperty.call(vue, '$act')) {
107
- vue.act = actMaster;
108
- vue.prototype.$act = actMaster;
109
- }
110
- }
111
- install(vue, options) {
112
- VueActMaster.install(vue, options);
113
- }
114
- }
115
- VueActMaster.instance = null;
116
-
117
- export { ActInProgress, ActSubscribe, VueActMaster };
@@ -1 +0,0 @@
1
- import{ActMaster as t}from"act-master";export*from"act-master";function n(t){return(n,o,i)=>{const e="function"==typeof n?n:n.constructor;e.__decorators__||(e.__decorators__=[]),"number"!=typeof i&&(i=void 0),e.__decorators__.push((n=>t(n,o,i)))}}function o(t,o,i=null){return n(((n,e)=>{const s={created(){this.$act.subscribe(t,(t=>{const n=function(t,n,o){if(void 0===t)return o;if("function"==typeof n)return n(t);let i=t;if(n){const t=(n||"").split(".");let o,e=0;for(e=0;e<t.length&&i;e++)o=t[e],i=i[o]}if(void 0===i)return o;return i}(t,o,i);"function"==typeof this[e]?this[e](n):this[e]=n}),this)}};n.mixins?n.mixins=[...n.mixins,s]:n.mixins=[s]}))}function i(t){return n(((n,o)=>{const i={created(){const n=this.$act.inProgress(t,(t=>{this[o]=t}));this.$once("hook:beforeDestroy",(()=>{n(t)}))}};n.mixins?n.mixins=[...n.mixins,i]:n.mixins=[i]}))}class e{static install(n,o){var i;const s=new t(Object.assign({autoUnsubscribeCallback({context:t,eventName:n,listener:o}){t&&"function"==typeof t?t((function(){s.unsubscribe(n,o)})):t&&"function"==typeof t.$once&&t.$once("hook:beforeDestroy",(()=>{s.unsubscribe(n,o)}))}},o));e.instance=s,(null===(i=n.config)||void 0===i?void 0:i.globalProperties)&&!n.config.globalProperties.$act?(n.config.globalProperties.$act=s,n.provide("$act",s)):Object.prototype.hasOwnProperty.call(n,"$act")||(n.act=s,n.prototype.$act=s)}install(t,n){e.install(t,n)}}e.instance=null;export{i as ActInProgress,o as ActSubscribe,e as VueActMaster};
package/dist/index.umd.js DELETED
@@ -1,132 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('act-master')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'act-master'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["vue-act-master"] = {}, global.actMaster));
5
- })(this, (function (exports, actMaster) { 'use strict';
6
-
7
- function createDecorator(factory) {
8
- return (target, key, index) => {
9
- const Ctor = typeof target === 'function'
10
- ? target
11
- : target.constructor;
12
- if (!Ctor.__decorators__) {
13
- Ctor.__decorators__ = [];
14
- }
15
- if (typeof index !== 'number') {
16
- index = undefined;
17
- }
18
- Ctor.__decorators__.push((options) => factory(options, key, index));
19
- };
20
- }
21
-
22
- function ActSubscribe(eventName, pathToData, defaultValue = null) {
23
- return createDecorator((componentOptions, key) => {
24
- const subscribeHook = {
25
- created() {
26
- this.$act.subscribe(eventName, (data) => {
27
- const value = objectPath(data, pathToData, defaultValue);
28
- if (typeof this[key] === 'function') {
29
- this[key](value);
30
- }
31
- else {
32
- this[key] = value;
33
- }
34
- }, this);
35
- },
36
- };
37
- if (componentOptions.mixins) {
38
- componentOptions.mixins = [...componentOptions.mixins, subscribeHook];
39
- }
40
- else {
41
- componentOptions.mixins = [subscribeHook];
42
- }
43
- });
44
- }
45
- function objectPath(obj, path, defaultValue) {
46
- if (obj === undefined) {
47
- return defaultValue;
48
- }
49
- if (typeof path === 'function') {
50
- return path(obj);
51
- }
52
- let value = obj;
53
- if (path) {
54
- const list = (path || '').split('.');
55
- let key;
56
- let i = 0;
57
- for (i = 0; i < list.length && value; i++) {
58
- key = list[i];
59
- value = value[key];
60
- }
61
- }
62
- if (value === undefined) {
63
- return defaultValue;
64
- }
65
- return value;
66
- }
67
-
68
- function ActInProgress(eventName) {
69
- return createDecorator((componentOptions, key) => {
70
- const inProgressHook = {
71
- created() {
72
- const unsubscribe = this.$act.inProgress(eventName, (inProgress) => {
73
- this[key] = inProgress;
74
- });
75
- this.$once('hook:beforeDestroy', () => {
76
- unsubscribe(eventName);
77
- });
78
- },
79
- };
80
- if (componentOptions.mixins) {
81
- componentOptions.mixins = [...componentOptions.mixins, inProgressHook];
82
- }
83
- else {
84
- componentOptions.mixins = [inProgressHook];
85
- }
86
- });
87
- }
88
-
89
- class VueActMaster {
90
- static install(vue, options) {
91
- var _a;
92
- const actMaster$1 = new actMaster.ActMaster(Object.assign({ autoUnsubscribeCallback({ context, eventName, listener }) {
93
- if (context && typeof context === 'function') {
94
- context(function () {
95
- actMaster$1.unsubscribe(eventName, listener);
96
- });
97
- }
98
- else if (context && typeof context.$once === 'function') {
99
- context.$once('hook:beforeDestroy', () => {
100
- actMaster$1.unsubscribe(eventName, listener);
101
- });
102
- }
103
- } }, options));
104
- VueActMaster.instance = actMaster$1;
105
- if (((_a = vue.config) === null || _a === void 0 ? void 0 : _a.globalProperties) && !vue.config.globalProperties.$act) {
106
- vue.config.globalProperties.$act = actMaster$1;
107
- vue.provide('$act', actMaster$1);
108
- }
109
- else if (!Object.prototype.hasOwnProperty.call(vue, '$act')) {
110
- vue.act = actMaster$1;
111
- vue.prototype.$act = actMaster$1;
112
- }
113
- }
114
- install(vue, options) {
115
- VueActMaster.install(vue, options);
116
- }
117
- }
118
- VueActMaster.instance = null;
119
-
120
- exports.ActInProgress = ActInProgress;
121
- exports.ActSubscribe = ActSubscribe;
122
- exports.VueActMaster = VueActMaster;
123
- Object.keys(actMaster).forEach(function (k) {
124
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
125
- enumerable: true,
126
- get: function () { return actMaster[k]; }
127
- });
128
- });
129
-
130
- Object.defineProperty(exports, '__esModule', { value: true });
131
-
132
- }));
@@ -1 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("act-master")):"function"==typeof define&&define.amd?define(["exports","act-master"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["vue-act-master"]={},t.actMaster)}(this,(function(t,e){"use strict";function n(t){return(e,n,o)=>{const i="function"==typeof e?e:e.constructor;i.__decorators__||(i.__decorators__=[]),"number"!=typeof o&&(o=void 0),i.__decorators__.push((e=>t(e,n,o)))}}class o{static install(t,n){var i;const s=new e.ActMaster(Object.assign({autoUnsubscribeCallback({context:t,eventName:e,listener:n}){t&&"function"==typeof t?t((function(){s.unsubscribe(e,n)})):t&&"function"==typeof t.$once&&t.$once("hook:beforeDestroy",(()=>{s.unsubscribe(e,n)}))}},n));o.instance=s,(null===(i=t.config)||void 0===i?void 0:i.globalProperties)&&!t.config.globalProperties.$act?(t.config.globalProperties.$act=s,t.provide("$act",s)):Object.prototype.hasOwnProperty.call(t,"$act")||(t.act=s,t.prototype.$act=s)}install(t,e){o.install(t,e)}}o.instance=null,t.ActInProgress=function(t){return n(((e,n)=>{const o={created(){const e=this.$act.inProgress(t,(t=>{this[n]=t}));this.$once("hook:beforeDestroy",(()=>{e(t)}))}};e.mixins?e.mixins=[...e.mixins,o]:e.mixins=[o]}))},t.ActSubscribe=function(t,e,o=null){return n(((n,i)=>{const s={created(){this.$act.subscribe(t,(t=>{const n=function(t,e,n){if(void 0===t)return n;if("function"==typeof e)return e(t);let o=t;if(e){const t=(e||"").split(".");let n,i=0;for(i=0;i<t.length&&o;i++)n=t[i],o=o[n]}if(void 0===o)return n;return o}(t,e,o);"function"==typeof this[i]?this[i](n):this[i]=n}),this)}};n.mixins?n.mixins=[...n.mixins,s]:n.mixins=[s]}))},t.VueActMaster=o,Object.keys(e).forEach((function(n){"default"===n||t.hasOwnProperty(n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})})),Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,3 +0,0 @@
1
- import { ActEventName } from 'act-master';
2
- import { VueDecorator } from './helpers';
3
- export declare function ActInProgress(eventName: ActEventName | ActEventName[]): VueDecorator;
@@ -1,6 +0,0 @@
1
- import { ActEventName } from 'act-master';
2
- import { VueDecorator } from './helpers';
3
- export declare function ActSubscribe(eventName: ActEventName, pathToData?: PathToData, defaultValue?: unknown): VueDecorator;
4
- declare type GetValueCallback = (value: any) => any;
5
- declare type PathToData = string | null | GetValueCallback;
6
- export {};
@@ -1,10 +0,0 @@
1
- import { ComponentOptions } from 'vue';
2
- declare type Vue = any;
3
- export interface VueDecorator {
4
- (Ctor: any): void;
5
- (target: Vue, key: string): void;
6
- (target: Vue, key: string, index: number): void;
7
- }
8
- export declare function createDecorator(factory: (options: ComponentOptions<Vue>, key: string, index: number) => void): VueDecorator;
9
- export declare function objectPath(obj: any, path: string | null, defaultValue: unknown): any;
10
- export {};
@@ -1,2 +0,0 @@
1
- export * from './act-subscribe';
2
- export * from './act-in-progress';
@@ -1,21 +0,0 @@
1
- import { ActMaster, ActMasterOptions } from 'act-master';
2
- export * from 'act-master';
3
- export * from './decorators';
4
- declare module 'vue/types/vue' {
5
- interface Vue {
6
- $act: ActMaster;
7
- }
8
- interface VueConstructor {
9
- act: ActMaster;
10
- }
11
- }
12
- declare module '@vue/runtime-core' {
13
- interface ComponentCustomProperties {
14
- $act: ActMaster;
15
- }
16
- }
17
- export declare class VueActMaster {
18
- static instance: ActMaster | null;
19
- static install(vue: any, options?: ActMasterOptions): void;
20
- install(vue: any, options?: ActMasterOptions): void;
21
- }
@@ -1 +0,0 @@
1
- export declare function debounce(func: (...args: any[]) => void, wait?: number, args?: any, _prefix?: string): void;