vue-act-master 2.0.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.
@@ -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": "2.0.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,24 +52,17 @@
43
52
  },
44
53
  "license": "MIT",
45
54
  "dependencies": {
46
- "act-master": "^2.0.0"
55
+ "act-master": "^2.0.1"
47
56
  },
48
57
  "peerDependencies": {
49
- "act-master": "^2.0.0"
58
+ "act-master": "^2.0.1"
50
59
  },
51
60
  "devDependencies": {
52
- "@types/node": "^20.1.7",
53
- "@typescript-eslint/eslint-plugin": "^5.59.6",
61
+ "@babel/types": "^7.22.5",
54
62
  "auto-changelog": "^2.4.0",
55
- "eslint": "^8.40.0",
56
- "eslint-config-prettier": "^8.8.0",
57
- "eslint-plugin-prettier": "^4.2.1",
58
- "prettier": "^2.8.8",
59
- "rollup": "^2.57.0",
60
- "rollup-plugin-filesize": "^9.1.1",
61
- "rollup-plugin-terser": "^7.0.2",
62
- "rollup-plugin-typescript2": "^0.30.0",
63
63
  "typescript": "^5.0.4",
64
+ "vite": "^4.3.7",
65
+ "vitest": "^0.31.0",
64
66
  "vue": "*"
65
67
  }
66
68
  }
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,130 +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
- const actMaster$1 = new actMaster.ActMaster({
92
- 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
- },
104
- ...options,
105
- });
106
- VueActMaster.instance = actMaster$1;
107
- if (vue.config?.globalProperties && !vue.config.globalProperties.$act) {
108
- vue.config.globalProperties.$act = actMaster$1;
109
- vue.provide('$act', actMaster$1);
110
- }
111
- else if (!Object.prototype.hasOwnProperty.call(vue, '$act')) {
112
- vue.act = actMaster$1;
113
- vue.prototype.$act = actMaster$1;
114
- }
115
- }
116
- install(vue, options) {
117
- VueActMaster.install(vue, options);
118
- }
119
- }
120
- VueActMaster.instance = null;
121
-
122
- exports.ActInProgress = ActInProgress;
123
- exports.ActSubscribe = ActSubscribe;
124
- exports.VueActMaster = VueActMaster;
125
- Object.keys(actMaster).forEach(function (k) {
126
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
127
- enumerable: true,
128
- get: function () { return actMaster[k]; }
129
- });
130
- });
package/dist/index.umd.js DELETED
@@ -1,134 +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
- const actMaster$1 = new actMaster.ActMaster({
92
- 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
- },
104
- ...options,
105
- });
106
- VueActMaster.instance = actMaster$1;
107
- if (vue.config?.globalProperties && !vue.config.globalProperties.$act) {
108
- vue.config.globalProperties.$act = actMaster$1;
109
- vue.provide('$act', actMaster$1);
110
- }
111
- else if (!Object.prototype.hasOwnProperty.call(vue, '$act')) {
112
- vue.act = actMaster$1;
113
- vue.prototype.$act = actMaster$1;
114
- }
115
- }
116
- install(vue, options) {
117
- VueActMaster.install(vue, options);
118
- }
119
- }
120
- VueActMaster.instance = null;
121
-
122
- exports.ActInProgress = ActInProgress;
123
- exports.ActSubscribe = ActSubscribe;
124
- exports.VueActMaster = VueActMaster;
125
- Object.keys(actMaster).forEach(function (k) {
126
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
127
- enumerable: true,
128
- get: function () { return actMaster[k]; }
129
- });
130
- });
131
-
132
- Object.defineProperty(exports, '__esModule', { value: true });
133
-
134
- }));