epos-unit 1.0.5 → 1.0.6

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.
@@ -3,9 +3,10 @@ import { epos } from 'epos';
3
3
  export declare const _root_: unique symbol;
4
4
  export declare const _parent_: unique symbol;
5
5
  export declare const _disposers_: unique symbol;
6
+ export type Descriptors = Record<string | symbol, PropertyDescriptor>;
6
7
  export declare class Unit<TRoot = unknown> {
7
8
  '@': string;
8
- 'log': Log;
9
+ log: Log;
9
10
  private [_root_];
10
11
  private [_parent_];
11
12
  private [_disposers_];
package/dist/epos-unit.js CHANGED
@@ -14,14 +14,15 @@ export class Unit {
14
14
  [epos.state.symbols.model.init]() {
15
15
  const Unit = this.constructor;
16
16
  const descriptors = Object.getOwnPropertyDescriptors(Unit.prototype);
17
- // Set disposers container
17
+ const keys = Reflect.ownKeys(descriptors);
18
+ // Setup disposers container
18
19
  const disposers = new Set();
19
20
  Reflect.defineProperty(this, _disposers_, { get: () => disposers });
20
21
  // Bind all methods
21
- for (const key in descriptors) {
22
- const descriptor = descriptors[key];
22
+ for (const key of keys) {
23
23
  if (key === 'constructor')
24
24
  continue;
25
+ const descriptor = descriptors[key];
25
26
  if (descriptor.get || descriptor.set)
26
27
  continue;
27
28
  if (typeof descriptor.value !== 'function')
@@ -29,16 +30,18 @@ export class Unit {
29
30
  this[key] = descriptor.value.bind(this);
30
31
  }
31
32
  // Wrap UI methods to components
32
- for (const key in descriptors) {
33
- const descriptor = descriptors[key];
33
+ for (const key of keys) {
34
+ if (typeof key === 'symbol')
35
+ continue;
34
36
  if (!key.startsWith('ui'))
35
37
  continue;
38
+ const descriptor = descriptors[key];
36
39
  if (descriptor.get || descriptor.set)
37
40
  continue;
38
- if (typeof descriptor.value !== 'function')
41
+ if (typeof this[key] !== 'function')
39
42
  continue;
40
43
  const componentName = [this['@'], key.replace('ui', '')].filter(Boolean).join('-');
41
- this[key] = epos.component(componentName, descriptor.value);
44
+ this[key] = epos.component(componentName, this[key]);
42
45
  }
43
46
  // Define log method
44
47
  const log = createLog(this['@']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epos-unit",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "imkost",