watch-state 3.4.2 → 3.4.3

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/Event/Event.d.ts CHANGED
@@ -23,3 +23,4 @@ export declare class Event {
23
23
  * */
24
24
  update(): void;
25
25
  }
26
+ export declare const globalEvent: Event;
@@ -1,4 +1,4 @@
1
- import { scope, globalEvent } from '../constants.es6.js';
1
+ import { scope } from '../constants.es6.js';
2
2
 
3
3
  class Event {
4
4
  add(target) {
@@ -63,6 +63,7 @@ class Event {
63
63
  }
64
64
  }
65
65
  }
66
- }
66
+ }
67
+ const globalEvent = new Event();
67
68
 
68
- export { Event };
69
+ export { Event, globalEvent };
package/Event/Event.js CHANGED
@@ -57,16 +57,18 @@ class Event {
57
57
  update() {
58
58
  var _a;
59
59
  if ((_a = this.watchers) === null || _a === void 0 ? void 0 : _a.size) {
60
- if (this === constants.globalEvent) {
60
+ if (this === globalEvent) {
61
61
  this.forceUpdate();
62
62
  }
63
63
  else {
64
- constants.globalEvent.start();
64
+ globalEvent.start();
65
65
  this.forceUpdate();
66
- constants.globalEvent.end();
66
+ globalEvent.end();
67
67
  }
68
68
  }
69
69
  }
70
- }
70
+ }
71
+ const globalEvent = new Event();
71
72
 
72
73
  exports.Event = Event;
74
+ exports.globalEvent = globalEvent;
@@ -1 +1 @@
1
- export { Event } from './Event.es6.js';
1
+ export { Event, globalEvent } from './Event.es6.js';
package/Event/index.js CHANGED
@@ -7,3 +7,4 @@ var Event = require('./Event.js');
7
7
 
8
8
 
9
9
  exports.Event = Event.Event;
10
+ exports.globalEvent = Event.globalEvent;
package/constants.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { Event } from './Event';
2
1
  import { Scope } from './types';
3
- export declare const globalEvent: Event;
4
2
  export declare const scope: Scope;
package/constants.es6.js CHANGED
@@ -1,10 +1,7 @@
1
- import { Event } from './Event/Event.es6.js';
2
-
3
- const globalEvent = new Event();
4
1
  const scope = {
5
2
  activeWatcher: undefined,
6
3
  activeEvent: undefined,
7
4
  activeEventDeep: 0,
8
5
  };
9
6
 
10
- export { globalEvent, scope };
7
+ export { scope };
package/constants.js CHANGED
@@ -2,14 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var Event = require('./Event/Event.js');
6
-
7
- const globalEvent = new Event.Event();
8
5
  const scope = {
9
6
  activeWatcher: undefined,
10
7
  activeEvent: undefined,
11
8
  activeEventDeep: 0,
12
9
  };
13
10
 
14
- exports.globalEvent = globalEvent;
15
11
  exports.scope = scope;
package/index.es6.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Watch } from './Watch/Watch.es6.js';
2
2
  export { State } from './State/State.es6.js';
3
3
  export { Cache } from './Cache/Cache.es6.js';
4
- export { Event } from './Event/Event.es6.js';
4
+ export { Event, globalEvent } from './Event/Event.es6.js';
5
5
  export { onDestroy } from './utils/onDestroy/onDestroy.es6.js';
6
6
  export { createEvent } from './utils/createEvent/createEvent.es6.js';
7
- export { globalEvent, scope } from './constants.es6.js';
7
+ export { scope } from './constants.es6.js';
package/index.js CHANGED
@@ -16,7 +16,7 @@ exports.Watch = Watch.Watch;
16
16
  exports.State = State.State;
17
17
  exports.Cache = Cache.Cache;
18
18
  exports.Event = Event.Event;
19
+ exports.globalEvent = Event.globalEvent;
19
20
  exports.onDestroy = onDestroy.onDestroy;
20
21
  exports.createEvent = createEvent.createEvent;
21
- exports.globalEvent = constants.globalEvent;
22
22
  exports.scope = constants.scope;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watch-state",
3
- "version": "3.4.2",
3
+ "version": "3.4.3",
4
4
  "description": "CANT inc. state management system.",
5
5
  "author": "Mikhail Lysikov <d8corp@mail.ru>",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- import { globalEvent } from '../../constants.es6.js';
1
+ import { globalEvent } from '../../Event/Event.es6.js';
2
2
 
3
3
  /**
4
4
  * You can create event function with createEvent
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var constants = require('../../constants.js');
5
+ var Event = require('../../Event/Event.js');
6
6
 
7
7
  /**
8
8
  * You can create event function with createEvent
@@ -19,9 +19,9 @@ var constants = require('../../constants.js');
19
19
  * */
20
20
  function createEvent(fn) {
21
21
  return function () {
22
- constants.globalEvent.start();
22
+ Event.globalEvent.start();
23
23
  const result = fn.apply(this, arguments);
24
- constants.globalEvent.end();
24
+ Event.globalEvent.end();
25
25
  return result;
26
26
  };
27
27
  }
@@ -1 +1 @@
1
- var watchState=function(t){"use strict";class e{add(t){let{watchers:e}=this;if(e){if(e.has(t))return;e.add(t)}else e=this.watchers=new Set([t]);t.onClear((()=>e.delete(t)))}start(){a.activeEvent||(this.activeWatcher=a.activeWatcher,a.activeWatcher=void 0,a.activeEvent=this),a.activeEventDeep++}end(){--a.activeEventDeep||a.activeEvent!==this||(a.activeEvent=void 0,this.update(),a.activeWatcher=this.activeWatcher)}forceUpdate(){const{watchers:t}=this;this.watchers=void 0;for(const e of t)e.update()}update(){var t;(null===(t=this.watchers)||void 0===t?void 0:t.size)&&(this===s?this.forceUpdate():(s.start(),this.forceUpdate(),s.end()))}}const s=new e,a={activeWatcher:void 0,activeEvent:void 0,activeEventDeep:0};function i(t){a.activeWatcher&&a.activeWatcher.onClear(t)}class r{constructor(t,e,s){this.watcher=t,this.ran=!1,e||i((()=>this.destroy())),s||this.watchRun()}run(){const{ran:t}=this;return this.ran=!0,this.watcher(t)}watchRun(){const t=a.activeWatcher;a.activeWatcher=this,this.run(),a.activeWatcher=t}forceUpdate(){this.destroy(),this.watchRun()}update(){this.destroy(),a.activeEvent?a.activeEvent.add(this):this.watchRun()}destroy(){const{destructors:t}=this;t&&(this.destructors=void 0,t.forEach((t=>t())))}onClear(t){return this.destructors?this.destructors.push(t):this.destructors=[t],this}onDestroy(t){return this.onClear(t)}}class h extends e{constructor(t){super(),this.state=t}get value(){return a.activeWatcher&&this.add(a.activeWatcher),this.state}set value(t){t!==this.state&&(this.state=t,this.update())}}class c extends r{constructor(t,e,s){super(t,e,!s)}destroy(){return super.destroy()}run(){this.updated=!0,this.value=super.run()}get hasWatcher(){if(this.updated&&this.size)for(const t of this._state.watchers)if(!(t instanceof c)||t.hasWatcher)return!0}get size(){var t,e;return null===(e=null===(t=this._state)||void 0===t?void 0:t.watchers)||void 0===e?void 0:e.size}deepUpdate(){if(this.updated=!1,this.destroy(),this.size)for(const t of this._state.watchers)t.deepUpdate()}update(){this.updated&&(this.hasWatcher?this.forceUpdate():this.deepUpdate())}get state(){return this._state||(this._state=new h)}get value(){return this.updated||this.forceUpdate(),this.state.value}set value(t){this.state.value=t}}return t.Cache=c,t.Event=e,t.State=h,t.Watch=r,t.createEvent=function(t){return function(){s.start();const e=t.apply(this,arguments);return s.end(),e}},t.globalEvent=s,t.onDestroy=i,t.scope=a,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
1
+ var watchState=function(t){"use strict";const e={activeWatcher:void 0,activeEvent:void 0,activeEventDeep:0};function s(t){e.activeWatcher&&e.activeWatcher.onClear(t)}class a{add(t){let{watchers:e}=this;if(e){if(e.has(t))return;e.add(t)}else e=this.watchers=new Set([t]);t.onClear((()=>e.delete(t)))}start(){e.activeEvent||(this.activeWatcher=e.activeWatcher,e.activeWatcher=void 0,e.activeEvent=this),e.activeEventDeep++}end(){--e.activeEventDeep||e.activeEvent!==this||(e.activeEvent=void 0,this.update(),e.activeWatcher=this.activeWatcher)}forceUpdate(){const{watchers:t}=this;this.watchers=void 0;for(const e of t)e.update()}update(){var t;(null===(t=this.watchers)||void 0===t?void 0:t.size)&&(this===i?this.forceUpdate():(i.start(),this.forceUpdate(),i.end()))}}const i=new a;class r{constructor(t,e,a){this.watcher=t,this.ran=!1,e||s((()=>this.destroy())),a||this.watchRun()}run(){const{ran:t}=this;return this.ran=!0,this.watcher(t)}watchRun(){const t=e.activeWatcher;e.activeWatcher=this,this.run(),e.activeWatcher=t}forceUpdate(){this.destroy(),this.watchRun()}update(){this.destroy(),e.activeEvent?e.activeEvent.add(this):this.watchRun()}destroy(){const{destructors:t}=this;t&&(this.destructors=void 0,t.forEach((t=>t())))}onClear(t){return this.destructors?this.destructors.push(t):this.destructors=[t],this}onDestroy(t){return this.onClear(t)}}class h extends a{constructor(t){super(),this.state=t}get value(){return e.activeWatcher&&this.add(e.activeWatcher),this.state}set value(t){t!==this.state&&(this.state=t,this.update())}}class c extends r{constructor(t,e,s){super(t,e,!s)}destroy(){return super.destroy()}run(){this.updated=!0,this.value=super.run()}get hasWatcher(){if(this.updated&&this.size)for(const t of this._state.watchers)if(!(t instanceof c)||t.hasWatcher)return!0}get size(){var t,e;return null===(e=null===(t=this._state)||void 0===t?void 0:t.watchers)||void 0===e?void 0:e.size}deepUpdate(){if(this.updated=!1,this.destroy(),this.size)for(const t of this._state.watchers)t.deepUpdate()}update(){this.updated&&(this.hasWatcher?this.forceUpdate():this.deepUpdate())}get state(){return this._state||(this._state=new h)}get value(){return this.updated||this.forceUpdate(),this.state.value}set value(t){this.state.value=t}}return t.Cache=c,t.Event=a,t.State=h,t.Watch=r,t.createEvent=function(t){return function(){i.start();const e=t.apply(this,arguments);return i.end(),e}},t.globalEvent=i,t.onDestroy=s,t.scope=e,Object.defineProperty(t,"__esModule",{value:!0}),t}({});