mirta 0.1.0 → 0.1.2

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Event } from '@mirta/basics';
1
+ import { OnEvent } from '@mirta/basics';
2
2
  export * from '@mirta/basics';
3
3
 
4
4
  type DeviceType = 'wired' | 'virtual' | 'zigbee';
@@ -91,9 +91,9 @@ interface Control<TValue> {
91
91
  /** Актуальное значение контрола. */
92
92
  value: TValue;
93
93
  /** Событие, происходящее когда поступило новое значение. */
94
- valueReceived: Event<ValueEventHandler<TValue>>;
94
+ onValueReceived: OnEvent<ValueEventHandler<TValue>>;
95
95
  /** Событие, происходящее когда значение изменилось. */
96
- valueChanged: Event<ValueEventHandler<TValue>>;
96
+ onValueChanged: OnEvent<ValueEventHandler<TValue>>;
97
97
  }
98
98
  type MaybeReadonlyControl<TValue, TReadonly extends boolean | undefined> = ReadonlyPropWhen<Control<TValue>, 'value', TReadonly>;
99
99
 
package/dist/index.mjs CHANGED
@@ -56,18 +56,18 @@ function createControl(context, controlId, options) {
56
56
  };
57
57
  const valueReceived = useEvent();
58
58
  const valueChanged = useEvent();
59
- let value;
59
+ let localValue;
60
60
  /**
61
61
  * Устанавливает новое значение, если оно отличается от существующего.
62
62
  * @param newValue Устанавливаемое значение.
63
63
  * @param preventEmit Предотвращает отправку значения в устройство.
64
64
  **/
65
65
  function setValue(newValue, preventEmit = false) {
66
- const oldValue = value;
66
+ const oldValue = localValue;
67
67
  valueReceived.raise(newValue, oldValue);
68
68
  if (oldValue === newValue)
69
69
  return;
70
- value = newValue;
70
+ localValue = newValue;
71
71
  if (!preventEmit)
72
72
  emitValue(newValue);
73
73
  valueChanged.raise(newValue, oldValue);
@@ -93,13 +93,13 @@ function createControl(context, controlId, options) {
93
93
  });
94
94
  return {
95
95
  get value() {
96
- if (value === undefined) {
96
+ if (localValue === undefined) {
97
97
  if (options.forceDefault)
98
- return value = defaultValue;
98
+ return localValue = defaultValue;
99
99
  if (!options.lazyInit)
100
- return value ??= control.safe?.getValue();
100
+ return localValue ??= control.safe?.getValue();
101
101
  }
102
- return value;
102
+ return localValue;
103
103
  },
104
104
  set value(newValue) {
105
105
  if (isReadonly) {
@@ -108,10 +108,8 @@ function createControl(context, controlId, options) {
108
108
  }
109
109
  setValue(newValue);
110
110
  },
111
- valueReceived: valueReceived
112
- .withoutRaise(),
113
- valueChanged: valueChanged
114
- .withoutRaise(),
111
+ onValueReceived: valueReceived.on,
112
+ onValueChanged: valueChanged.on,
115
113
  };
116
114
  }
117
115
 
@@ -221,6 +219,8 @@ function createDevice(deviceType, deviceId, propDefs, props, options) {
221
219
  type: controlDef.type,
222
220
  defaultValue: controlDef.defaultValue,
223
221
  isReadonly: controlDef.isReadonly,
222
+ forceDefault: controlDef.forceDefault,
223
+ lazyInit: controlDef.lazyInit,
224
224
  });
225
225
  controls[key] = control;
226
226
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mirta",
3
3
  "description": "The powerful framework to write smart home automation scripts.",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "license": "Unlicense",
6
6
  "keywords": [
7
7
  "mirta",
@@ -36,9 +36,9 @@
36
36
  "url": "https://pay.cloudtips.ru/p/58512cca"
37
37
  },
38
38
  "dependencies": {
39
- "@mirta/basics": "0.1.0",
40
- "@mirta/globals": "0.1.0",
41
- "@mirta/polyfills": "0.1.0"
39
+ "@mirta/globals": "0.1.2",
40
+ "@mirta/polyfills": "0.1.2",
41
+ "@mirta/basics": "0.1.2"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"