epos-unit 1.8.0 → 1.10.0

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.
@@ -1,25 +1,26 @@
1
1
  import * as mobx from 'mobx';
2
- import { Log, Cls } from '@eposlabs/utils';
2
+ import { Cls } from 'eposlabs/types';
3
+ import { Log } from 'eposlabs/utils';
3
4
 
4
5
  declare const _root_: unique symbol;
5
6
  declare const _parent_: unique symbol;
6
7
  declare const _disposers_: unique symbol;
7
8
  type Descriptors = Record<string | symbol, PropertyDescriptor>;
8
9
  declare class Unit<TRoot = unknown> {
10
+ static [epos.symbols.stateModelStrict]: boolean;
11
+ static [epos.symbols.stateModelVersioner]: unknown;
12
+ [epos.symbols.stateModelInit]: () => void;
13
+ [epos.symbols.stateModelDispose]: () => void;
9
14
  '@': string;
10
15
  log: Log;
11
16
  [':version']?: number;
12
17
  private [_root_];
13
18
  private [_parent_];
14
19
  private [_disposers_];
15
- static get [epos.state.symbols.modelStrict](): boolean;
16
20
  constructor(parent: Unit<TRoot> | null);
17
- [epos.state.symbols.modelInit](): void;
18
- [epos.state.symbols.modelCleanup](): void;
19
- static get [epos.state.symbols.modelVersioner](): unknown;
20
21
  static defineVersioner(versioner: Record<number, (this: any, unit: any) => void>): Record<number, (this: any, unit: any) => void>;
21
22
  get $(): TRoot;
22
- up<T extends Unit>(Ancestor: Cls<T>): T | null;
23
+ closest<T extends Unit>(Ancestor: Cls<T>): T | null;
23
24
  autorun(...args: Parameters<typeof epos.libs.mobx.autorun>): mobx.IReactionDisposer;
24
25
  reaction(...args: Parameters<typeof epos.libs.mobx.reaction>): mobx.IReactionDisposer;
25
26
  setTimeout(...args: Parameters<typeof self.setTimeout>): number;
package/dist/epos-unit.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // src/epos-unit.ts
2
2
  import "epos";
3
- import { createLog } from "@eposlabs/utils";
4
- var _root_ = Symbol("root");
5
- var _parent_ = Symbol("parent");
6
- var _disposers_ = Symbol("disposers");
3
+ import { createLog } from "eposlabs/utils";
4
+ var _root_ = /* @__PURE__ */ Symbol("root");
5
+ var _parent_ = /* @__PURE__ */ Symbol("parent");
6
+ var _disposers_ = /* @__PURE__ */ Symbol("disposers");
7
7
  var Unit = class {
8
- static get [epos.state.symbols.modelStrict]() {
8
+ static get [epos.symbols.stateModelStrict]() {
9
9
  return true;
10
10
  }
11
11
  constructor(parent) {
@@ -14,7 +14,7 @@ var Unit = class {
14
14
  // ---------------------------------------------------------------------------
15
15
  // INIT
16
16
  // ---------------------------------------------------------------------------
17
- [epos.state.symbols.modelInit]() {
17
+ [epos.symbols.stateModelInit]() {
18
18
  const _this = this;
19
19
  const Unit2 = this.constructor;
20
20
  const descriptors = Object.getOwnPropertyDescriptors(Unit2.prototype);
@@ -30,30 +30,30 @@ var Unit = class {
30
30
  }
31
31
  for (const key of keys) {
32
32
  if (typeof key === "symbol") continue;
33
- if (!key.startsWith("ui")) continue;
33
+ if (!key.endsWith("View")) continue;
34
34
  const descriptor = descriptors[key];
35
35
  if (descriptor.get || descriptor.set) continue;
36
36
  if (typeof _this[key] !== "function") continue;
37
- const componentName = [this["@"], key.replace("ui", "")].filter(Boolean).join("-");
38
- _this[key] = epos.component(componentName, _this[key]);
37
+ _this[key] = epos.component(_this[key]);
38
+ _this[key].displayName = `${this["@"]}.${key}`;
39
39
  }
40
40
  const log = createLog(this["@"]);
41
41
  Reflect.defineProperty(this, "log", { get: () => log });
42
42
  if (typeof _this.init === "function") _this.init();
43
43
  }
44
44
  // ---------------------------------------------------------------------------
45
- // CLEANUP
45
+ // DISPOSE
46
46
  // ---------------------------------------------------------------------------
47
- [epos.state.symbols.modelCleanup]() {
47
+ [epos.symbols.stateModelDispose]() {
48
48
  const _this = this;
49
49
  this[_disposers_].forEach((disposer) => disposer());
50
50
  this[_disposers_].clear();
51
- if (typeof _this.cleanup === "function") _this.cleanup();
51
+ if (typeof _this.dispose === "function") _this.dispose();
52
52
  }
53
53
  // ---------------------------------------------------------------------------
54
54
  // VERSIONER
55
55
  // ---------------------------------------------------------------------------
56
- static get [epos.state.symbols.modelVersioner]() {
56
+ static get [epos.symbols.stateModelVersioner]() {
57
57
  if (!("versioner" in this)) return null;
58
58
  return this.versioner;
59
59
  }
@@ -70,7 +70,7 @@ var Unit = class {
70
70
  // ---------------------------------------------------------------------------
71
71
  // METHODS
72
72
  // ---------------------------------------------------------------------------
73
- up(Ancestor) {
73
+ closest(Ancestor) {
74
74
  let cursor = getParent(this);
75
75
  while (cursor) {
76
76
  if (cursor instanceof Ancestor) return cursor;
@@ -100,7 +100,7 @@ var Unit = class {
100
100
  }
101
101
  };
102
102
  function getParent(child) {
103
- return child[_parent_] ?? child[epos.state.symbols.parent];
103
+ return child[_parent_] ?? child[epos.symbols.stateParent];
104
104
  }
105
105
  function findRoot(unit) {
106
106
  let root = unit;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "epos-unit",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",
7
7
  "description": "",
8
8
  "keywords": [],
9
9
  "scripts": {
10
- "dev": "tsup --config ../tsup.config.ts --watch",
11
- "build": "tsup --config ../tsup.config.ts",
10
+ "dev": "tsup --config ../../tsup.config.ts --watch",
11
+ "build": "tsup --config ../../tsup.config.ts",
12
12
  "lint": "tsc --noEmit",
13
13
  "release": "sh -c 'npm version ${1:-minor} && npm run build && npm publish' --"
14
14
  },
@@ -24,7 +24,7 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "@eposlabs/utils": "^1.10.0",
28
- "epos": "^1.19.0"
27
+ "epos": "^1.26.0",
28
+ "eposlabs": "^1.15.0"
29
29
  }
30
30
  }
package/src/epos-unit.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import 'epos'
2
- import { createLog, type Cls, type Log } from '@eposlabs/utils'
2
+ import type { Cls } from 'eposlabs/types'
3
+ import { createLog, Log } from 'eposlabs/utils'
3
4
  import type { FC } from 'react'
4
5
 
5
6
  export const _root_ = Symbol('root')
@@ -15,7 +16,7 @@ export class Unit<TRoot = unknown> {
15
16
  declare private [_parent_]: Unit<TRoot> | null // Parent reference for not-yet-attached units
16
17
  declare private [_disposers_]: Set<() => void>
17
18
 
18
- static get [epos.state.symbols.modelStrict]() {
19
+ static get [epos.symbols.stateModelStrict]() {
19
20
  return true
20
21
  }
21
22
 
@@ -28,7 +29,7 @@ export class Unit<TRoot = unknown> {
28
29
  // INIT
29
30
  // ---------------------------------------------------------------------------
30
31
 
31
- [epos.state.symbols.modelInit]() {
32
+ [epos.symbols.stateModelInit]() {
32
33
  const _this = this as any
33
34
  const Unit = this.constructor
34
35
  const descriptors: Descriptors = Object.getOwnPropertyDescriptors(Unit.prototype)
@@ -47,15 +48,15 @@ export class Unit<TRoot = unknown> {
47
48
  _this[key] = descriptor.value.bind(this)
48
49
  }
49
50
 
50
- // Wrap UI methods to components
51
+ // Create components out of `View` methods
51
52
  for (const key of keys) {
52
53
  if (typeof key === 'symbol') continue
53
- if (!key.startsWith('ui')) continue
54
+ if (!key.endsWith('View')) continue
54
55
  const descriptor = descriptors[key]
55
56
  if (descriptor.get || descriptor.set) continue
56
57
  if (typeof _this[key] !== 'function') continue
57
- const componentName = [this['@'], key.replace('ui', '')].filter(Boolean).join('-')
58
- _this[key] = epos.component(componentName, _this[key] as FC)
58
+ _this[key] = epos.component(_this[key] as FC)
59
+ _this[key].displayName = `${this['@']}.${key}`
59
60
  }
60
61
 
61
62
  // Define log method
@@ -67,25 +68,25 @@ export class Unit<TRoot = unknown> {
67
68
  }
68
69
 
69
70
  // ---------------------------------------------------------------------------
70
- // CLEANUP
71
+ // DISPOSE
71
72
  // ---------------------------------------------------------------------------
72
73
 
73
- [epos.state.symbols.modelCleanup]() {
74
+ [epos.symbols.stateModelDispose]() {
74
75
  const _this = this as any
75
76
 
76
77
  // Call disposers
77
78
  this[_disposers_].forEach(disposer => disposer())
78
79
  this[_disposers_].clear()
79
80
 
80
- // Call cleanup method
81
- if (typeof _this.cleanup === 'function') _this.cleanup()
81
+ // Call dispose method
82
+ if (typeof _this.dispose === 'function') _this.dispose()
82
83
  }
83
84
 
84
85
  // ---------------------------------------------------------------------------
85
86
  // VERSIONER
86
87
  // ---------------------------------------------------------------------------
87
88
 
88
- static get [epos.state.symbols.modelVersioner]() {
89
+ static get [epos.symbols.stateModelVersioner]() {
89
90
  if (!('versioner' in this)) return null
90
91
  return this.versioner
91
92
  }
@@ -107,7 +108,7 @@ export class Unit<TRoot = unknown> {
107
108
  // METHODS
108
109
  // ---------------------------------------------------------------------------
109
110
 
110
- up<T extends Unit>(Ancestor: Cls<T>): T | null {
111
+ closest<T extends Unit>(Ancestor: Cls<T>): T | null {
111
112
  let cursor: unknown = getParent(this)
112
113
  while (cursor) {
113
114
  if (cursor instanceof Ancestor) return cursor
@@ -146,7 +147,7 @@ export class Unit<TRoot = unknown> {
146
147
  // ---------------------------------------------------------------------------
147
148
 
148
149
  function getParent(child: any) {
149
- return child[_parent_] ?? child[epos.state.symbols.parent]
150
+ return child[_parent_] ?? child[epos.symbols.stateParent]
150
151
  }
151
152
 
152
153
  function findRoot(unit: Unit) {