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 +1 -0
- package/Event/Event.es6.js +4 -3
- package/Event/Event.js +6 -4
- package/Event/index.es6.js +1 -1
- package/Event/index.js +1 -0
- package/constants.d.ts +0 -2
- package/constants.es6.js +1 -4
- package/constants.js +0 -4
- package/index.es6.js +2 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils/createEvent/createEvent.es6.js +1 -1
- package/utils/createEvent/createEvent.js +3 -3
- package/watch-state.min.js +1 -1
package/Event/Event.d.ts
CHANGED
package/Event/Event.es6.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { scope
|
|
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 ===
|
|
60
|
+
if (this === globalEvent) {
|
|
61
61
|
this.forceUpdate();
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
|
-
|
|
64
|
+
globalEvent.start();
|
|
65
65
|
this.forceUpdate();
|
|
66
|
-
|
|
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;
|
package/Event/index.es6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Event } from './Event.es6.js';
|
|
1
|
+
export { Event, globalEvent } from './Event.es6.js';
|
package/Event/index.js
CHANGED
package/constants.d.ts
CHANGED
package/constants.es6.js
CHANGED
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 {
|
|
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
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
|
-
|
|
22
|
+
Event.globalEvent.start();
|
|
23
23
|
const result = fn.apply(this, arguments);
|
|
24
|
-
|
|
24
|
+
Event.globalEvent.end();
|
|
25
25
|
return result;
|
|
26
26
|
};
|
|
27
27
|
}
|
package/watch-state.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var watchState=function(t){"use strict";
|
|
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}({});
|