@expressive/mvc 0.29.0 → 0.29.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/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
@@ -254,12 +254,14 @@ function createEffect(source, callback) {
254
254
  return () => refresh = null;
255
255
  });
256
256
  }
257
- function createValueEffect(callback) {
257
+ function createValueEffect(callback, ignoreNull) {
258
258
  let unSet;
259
259
  return function (value) {
260
260
  if (typeof unSet == "function")
261
- unSet(value);
262
- const out = callback.call(this, value, this);
261
+ unSet = void unSet(value);
262
+ if (value === null && ignoreNull)
263
+ return;
264
+ const out = callback.call(this, value);
263
265
  if (typeof out == "boolean")
264
266
  return out;
265
267
  if (!out || out instanceof Promise)
@@ -775,31 +777,30 @@ function flushComputed() {
775
777
  }
776
778
  Control.before.add(flushComputed);
777
779
 
778
- function ref(arg, mapper) {
780
+ function ref(arg, arg2) {
779
781
  return apply((key, source) => {
780
782
  let value = {};
781
- if (typeof arg != "object")
782
- value = createRef(source, key, arg);
783
- else
784
- for (const key in control(arg, true).state) {
785
- defineProperty(value, key, mapper ? {
783
+ if (typeof arg == "object")
784
+ for (const key in control(arg, true).state)
785
+ defineProperty(value, key, typeof arg2 == "function" ? {
786
786
  configurable: true,
787
787
  get() {
788
- const out = mapper(key);
788
+ const out = arg2(key);
789
789
  defineProperty(value, key, { value: out });
790
790
  return out;
791
791
  }
792
792
  } : {
793
793
  value: createRef(source, key)
794
794
  });
795
- }
795
+ else
796
+ value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
796
797
  source.state[key] = undefined;
797
798
  source.observers.set(key, new Set());
798
799
  defineProperty(source.subject, key, { value });
799
800
  });
800
801
  }
801
802
  function createRef(src, key, cb) {
802
- const refObjectFunction = src.ref(key, cb && createValueEffect(cb));
803
+ const refObjectFunction = src.ref(key, cb);
803
804
  defineProperty(refObjectFunction, "current", {
804
805
  set: refObjectFunction,
805
806
  get: () => src.state[key]
package/lib/index.js CHANGED
@@ -258,12 +258,14 @@ function createEffect(source, callback) {
258
258
  return () => refresh = null;
259
259
  });
260
260
  }
261
- function createValueEffect(callback) {
261
+ function createValueEffect(callback, ignoreNull) {
262
262
  let unSet;
263
263
  return function (value) {
264
264
  if (typeof unSet == "function")
265
- unSet(value);
266
- const out = callback.call(this, value, this);
265
+ unSet = void unSet(value);
266
+ if (value === null && ignoreNull)
267
+ return;
268
+ const out = callback.call(this, value);
267
269
  if (typeof out == "boolean")
268
270
  return out;
269
271
  if (!out || out instanceof Promise)
@@ -779,31 +781,30 @@ function flushComputed() {
779
781
  }
780
782
  Control.before.add(flushComputed);
781
783
 
782
- function ref(arg, mapper) {
784
+ function ref(arg, arg2) {
783
785
  return apply((key, source) => {
784
786
  let value = {};
785
- if (typeof arg != "object")
786
- value = createRef(source, key, arg);
787
- else
788
- for (const key in control(arg, true).state) {
789
- defineProperty(value, key, mapper ? {
787
+ if (typeof arg == "object")
788
+ for (const key in control(arg, true).state)
789
+ defineProperty(value, key, typeof arg2 == "function" ? {
790
790
  configurable: true,
791
791
  get() {
792
- const out = mapper(key);
792
+ const out = arg2(key);
793
793
  defineProperty(value, key, { value: out });
794
794
  return out;
795
795
  }
796
796
  } : {
797
797
  value: createRef(source, key)
798
798
  });
799
- }
799
+ else
800
+ value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
800
801
  source.state[key] = undefined;
801
802
  source.observers.set(key, new Set());
802
803
  defineProperty(source.subject, key, { value });
803
804
  });
804
805
  }
805
806
  function createRef(src, key, cb) {
806
- const refObjectFunction = src.ref(key, cb && createValueEffect(cb));
807
+ const refObjectFunction = src.ref(key, cb);
807
808
  defineProperty(refObjectFunction, "current", {
808
809
  set: refObjectFunction,
809
810
  get: () => src.state[key]
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.2",
30
+ "gitHead": "a10efcc0deba6e634d9b194ceda506573e981719"
31
31
  }