@expressive/mvc 0.29.0 → 0.29.1

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/lib/index.d.ts CHANGED
@@ -176,9 +176,9 @@ declare function get<R, T>(compute: (property: string, on: T) => (this: T, state
176
176
  declare function get<R, T>(compute: (property: string, on: T) => (this: T, state: T) => R): R;
177
177
 
178
178
  declare namespace ref {
179
- type Callback<T> = (argument: T) => ((next: T) => void) | Promise<void> | void | boolean;
179
+ type Callback<T> = (argument: T) => ((next: T | null) => void) | Promise<void> | void | boolean;
180
180
  interface Object<T = any> {
181
- (next: T): void;
181
+ (next: T | null): void;
182
182
  current: T | null;
183
183
  }
184
184
  /** Object with references to all managed values of `T`. */
@@ -216,6 +216,16 @@ declare function ref<O extends Model, R>(target: O, mapper: (key: Model.Key<O>)
216
216
  * @param callback - Optional callback to synchronously fire when reference is first set or does update.
217
217
  */
218
218
  declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
219
+ /**
220
+ * Creates a ref-compatible property.
221
+ * Will persist value, and updates to this are made part of controller event-stream.
222
+ *
223
+ * *Output is simultaneously a ref-function and ref-object, use as needed.*
224
+ *
225
+ * @param callback - Optional callback to synchronously fire when reference is first set or does update.
226
+ * @param ignoreNull - Default `true`. If `false`, will still callback with `null`.
227
+ */
228
+ declare function ref<T = HTMLElement>(callback: ref.Callback<T | null>, ignoreNull: boolean): ref.Object<T>;
219
229
 
220
230
  declare namespace set {
221
231
  type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
package/lib/index.esm.js CHANGED
@@ -259,7 +259,7 @@ function createValueEffect(callback) {
259
259
  return function (value) {
260
260
  if (typeof unSet == "function")
261
261
  unSet(value);
262
- const out = callback.call(this, value, this);
262
+ const out = callback.call(this, value);
263
263
  if (typeof out == "boolean")
264
264
  return out;
265
265
  if (!out || out instanceof Promise)
@@ -778,11 +778,9 @@ Control.before.add(flushComputed);
778
778
  function ref(arg, mapper) {
779
779
  return apply((key, source) => {
780
780
  let value = {};
781
- if (typeof arg != "object")
782
- value = createRef(source, key, arg);
783
- else
781
+ if (typeof arg == "object")
784
782
  for (const key in control(arg, true).state) {
785
- defineProperty(value, key, mapper ? {
783
+ defineProperty(value, key, typeof mapper == "function" ? {
786
784
  configurable: true,
787
785
  get() {
788
786
  const out = mapper(key);
@@ -793,6 +791,10 @@ function ref(arg, mapper) {
793
791
  value: createRef(source, key)
794
792
  });
795
793
  }
794
+ else
795
+ value = createRef(source, key, arg && mapper !== false
796
+ ? (x) => x !== null ? arg(x) : undefined
797
+ : arg);
796
798
  source.state[key] = undefined;
797
799
  source.observers.set(key, new Set());
798
800
  defineProperty(source.subject, key, { value });
package/lib/index.js CHANGED
@@ -263,7 +263,7 @@ function createValueEffect(callback) {
263
263
  return function (value) {
264
264
  if (typeof unSet == "function")
265
265
  unSet(value);
266
- const out = callback.call(this, value, this);
266
+ const out = callback.call(this, value);
267
267
  if (typeof out == "boolean")
268
268
  return out;
269
269
  if (!out || out instanceof Promise)
@@ -782,11 +782,9 @@ Control.before.add(flushComputed);
782
782
  function ref(arg, mapper) {
783
783
  return apply((key, source) => {
784
784
  let value = {};
785
- if (typeof arg != "object")
786
- value = createRef(source, key, arg);
787
- else
785
+ if (typeof arg == "object")
788
786
  for (const key in control(arg, true).state) {
789
- defineProperty(value, key, mapper ? {
787
+ defineProperty(value, key, typeof mapper == "function" ? {
790
788
  configurable: true,
791
789
  get() {
792
790
  const out = mapper(key);
@@ -797,6 +795,10 @@ function ref(arg, mapper) {
797
795
  value: createRef(source, key)
798
796
  });
799
797
  }
798
+ else
799
+ value = createRef(source, key, arg && mapper !== false
800
+ ? (x) => x !== null ? arg(x) : undefined
801
+ : arg);
800
802
  source.state[key] = undefined;
801
803
  source.observers.set(key, new Set());
802
804
  defineProperty(source.subject, key, { value });
package/package.json CHANGED
@@ -26,6 +26,6 @@
26
26
  "prebuild": "rm -rf lib/",
27
27
  "preversion": "npm run test && npm run build"
28
28
  },
29
- "version": "0.29.0",
30
- "gitHead": "3040fe38026dbff2d9c9e94aed2a46e8c057a137"
29
+ "version": "0.29.1",
30
+ "gitHead": "bc5ef985433d6f7d198eda375cda9e8a055ca0d0"
31
31
  }