grainjs 1.0.1 → 1.1.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.
Files changed (146) hide show
  1. package/README.md +23 -26
  2. package/dist/cjs/index.js +28 -17
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/lib/PriorityQueue.d.ts +2 -2
  5. package/dist/cjs/lib/PriorityQueue.js +1 -0
  6. package/dist/cjs/lib/PriorityQueue.js.map +1 -1
  7. package/dist/cjs/lib/_computed_queue.js +4 -3
  8. package/dist/cjs/lib/_computed_queue.js.map +1 -1
  9. package/dist/cjs/lib/binding.d.ts +11 -4
  10. package/dist/cjs/lib/binding.js +6 -5
  11. package/dist/cjs/lib/binding.js.map +1 -1
  12. package/dist/cjs/lib/browserGlobals.d.ts +4 -1
  13. package/dist/cjs/lib/browserGlobals.js +2 -0
  14. package/dist/cjs/lib/browserGlobals.js.map +1 -1
  15. package/dist/cjs/lib/computed.d.ts +49 -28
  16. package/dist/cjs/lib/computed.js +38 -51
  17. package/dist/cjs/lib/computed.js.map +1 -1
  18. package/dist/cjs/lib/dispose.d.ts +109 -96
  19. package/dist/cjs/lib/dispose.js +106 -79
  20. package/dist/cjs/lib/dispose.js.map +1 -1
  21. package/dist/cjs/lib/dom.d.ts +40 -18
  22. package/dist/cjs/lib/dom.js +63 -29
  23. package/dist/cjs/lib/dom.js.map +1 -1
  24. package/dist/cjs/lib/domComponent.d.ts +56 -51
  25. package/dist/cjs/lib/domComponent.js +46 -44
  26. package/dist/cjs/lib/domComponent.js.map +1 -1
  27. package/dist/cjs/lib/domComputed.d.ts +50 -20
  28. package/dist/cjs/lib/domComputed.js +37 -7
  29. package/dist/cjs/lib/domComputed.js.map +1 -1
  30. package/dist/cjs/lib/domDispose.d.ts +27 -12
  31. package/dist/cjs/lib/domDispose.js +27 -11
  32. package/dist/cjs/lib/domDispose.js.map +1 -1
  33. package/dist/cjs/lib/domForEach.d.ts +5 -4
  34. package/dist/cjs/lib/domForEach.js +41 -41
  35. package/dist/cjs/lib/domForEach.js.map +1 -1
  36. package/dist/cjs/lib/domImpl.d.ts +33 -10
  37. package/dist/cjs/lib/domImpl.js +29 -9
  38. package/dist/cjs/lib/domImpl.js.map +1 -1
  39. package/dist/cjs/lib/domMethods.d.ts +93 -47
  40. package/dist/cjs/lib/domMethods.js +91 -47
  41. package/dist/cjs/lib/domMethods.js.map +1 -1
  42. package/dist/cjs/lib/domevent.d.ts +87 -62
  43. package/dist/cjs/lib/domevent.js +85 -59
  44. package/dist/cjs/lib/domevent.js.map +1 -1
  45. package/dist/cjs/lib/emit.d.ts +62 -32
  46. package/dist/cjs/lib/emit.js +68 -53
  47. package/dist/cjs/lib/emit.js.map +1 -1
  48. package/dist/cjs/lib/kowrap.d.ts +6 -3
  49. package/dist/cjs/lib/kowrap.js +7 -3
  50. package/dist/cjs/lib/kowrap.js.map +1 -1
  51. package/dist/cjs/lib/obsArray.d.ts +91 -53
  52. package/dist/cjs/lib/obsArray.js +87 -54
  53. package/dist/cjs/lib/obsArray.js.map +1 -1
  54. package/dist/cjs/lib/observable.d.ts +25 -15
  55. package/dist/cjs/lib/observable.js +31 -19
  56. package/dist/cjs/lib/observable.js.map +1 -1
  57. package/dist/cjs/lib/pureComputed.d.ts +12 -15
  58. package/dist/cjs/lib/pureComputed.js +16 -18
  59. package/dist/cjs/lib/pureComputed.js.map +1 -1
  60. package/dist/cjs/lib/styled.d.ts +78 -61
  61. package/dist/cjs/lib/styled.js +27 -79
  62. package/dist/cjs/lib/styled.js.map +1 -1
  63. package/dist/cjs/lib/subscribe.d.ts +41 -37
  64. package/dist/cjs/lib/subscribe.js +31 -39
  65. package/dist/cjs/lib/subscribe.js.map +1 -1
  66. package/dist/cjs/lib/util.js +2 -0
  67. package/dist/cjs/lib/util.js.map +1 -1
  68. package/dist/cjs/lib/widgets/input.d.ts +3 -1
  69. package/dist/cjs/lib/widgets/input.js +7 -4
  70. package/dist/cjs/lib/widgets/input.js.map +1 -1
  71. package/dist/cjs/lib/widgets/select.d.ts +4 -2
  72. package/dist/cjs/lib/widgets/select.js +8 -5
  73. package/dist/cjs/lib/widgets/select.js.map +1 -1
  74. package/dist/esm/lib/_computed_queue.js +3 -3
  75. package/dist/esm/lib/_computed_queue.js.map +1 -1
  76. package/dist/esm/lib/binding.js +2 -2
  77. package/dist/esm/lib/binding.js.map +1 -1
  78. package/dist/esm/lib/browserGlobals.js +1 -0
  79. package/dist/esm/lib/browserGlobals.js.map +1 -1
  80. package/dist/esm/lib/computed.js +36 -50
  81. package/dist/esm/lib/computed.js.map +1 -1
  82. package/dist/esm/lib/dispose.js +104 -78
  83. package/dist/esm/lib/dispose.js.map +1 -1
  84. package/dist/esm/lib/dom.js +40 -18
  85. package/dist/esm/lib/dom.js.map +1 -1
  86. package/dist/esm/lib/domComponent.js +45 -44
  87. package/dist/esm/lib/domComponent.js.map +1 -1
  88. package/dist/esm/lib/domComputed.js +32 -5
  89. package/dist/esm/lib/domComputed.js.map +1 -1
  90. package/dist/esm/lib/domDispose.js +26 -11
  91. package/dist/esm/lib/domDispose.js.map +1 -1
  92. package/dist/esm/lib/domForEach.js +40 -41
  93. package/dist/esm/lib/domForEach.js.map +1 -1
  94. package/dist/esm/lib/domImpl.js +26 -7
  95. package/dist/esm/lib/domImpl.js.map +1 -1
  96. package/dist/esm/lib/domMethods.js +77 -35
  97. package/dist/esm/lib/domMethods.js.map +1 -1
  98. package/dist/esm/lib/domevent.js +84 -59
  99. package/dist/esm/lib/domevent.js.map +1 -1
  100. package/dist/esm/lib/emit.js +67 -53
  101. package/dist/esm/lib/emit.js.map +1 -1
  102. package/dist/esm/lib/kowrap.js +5 -2
  103. package/dist/esm/lib/kowrap.js.map +1 -1
  104. package/dist/esm/lib/obsArray.js +82 -50
  105. package/dist/esm/lib/obsArray.js.map +1 -1
  106. package/dist/esm/lib/observable.js +26 -15
  107. package/dist/esm/lib/observable.js.map +1 -1
  108. package/dist/esm/lib/pureComputed.js +15 -18
  109. package/dist/esm/lib/pureComputed.js.map +1 -1
  110. package/dist/esm/lib/styled.js +24 -77
  111. package/dist/esm/lib/styled.js.map +1 -1
  112. package/dist/esm/lib/subscribe.js +27 -36
  113. package/dist/esm/lib/subscribe.js.map +1 -1
  114. package/dist/esm/lib/util.js +1 -0
  115. package/dist/esm/lib/util.js.map +1 -1
  116. package/dist/esm/lib/widgets/input.js +3 -1
  117. package/dist/esm/lib/widgets/input.js.map +1 -1
  118. package/dist/esm/lib/widgets/select.js +3 -1
  119. package/dist/esm/lib/widgets/select.js.map +1 -1
  120. package/dist/grain-full.debug.js +2138 -3052
  121. package/dist/grain-full.debug.js.map +7 -0
  122. package/dist/grain-full.min.js +6 -2
  123. package/dist/grain-full.min.js.map +7 -1
  124. package/lib/binding.ts +9 -2
  125. package/lib/browserGlobals.ts +3 -1
  126. package/lib/computed.ts +56 -56
  127. package/lib/dispose.ts +110 -85
  128. package/lib/dom.ts +41 -20
  129. package/lib/domComponent.ts +68 -70
  130. package/lib/domComputed.ts +66 -21
  131. package/lib/domDispose.ts +28 -11
  132. package/lib/domForEach.ts +13 -12
  133. package/lib/domImpl.ts +30 -7
  134. package/lib/domMethods.ts +101 -46
  135. package/lib/domevent.ts +86 -61
  136. package/lib/emit.ts +64 -50
  137. package/lib/kowrap.ts +5 -2
  138. package/lib/obsArray.ts +89 -54
  139. package/lib/observable.ts +26 -15
  140. package/lib/pureComputed.ts +16 -22
  141. package/lib/styled.ts +85 -71
  142. package/lib/subscribe.ts +41 -45
  143. package/lib/util.ts +1 -0
  144. package/lib/widgets/input.ts +3 -1
  145. package/lib/widgets/select.ts +3 -1
  146. package/package.json +48 -38
@@ -1,43 +1,10 @@
1
1
  "use strict";
2
- /**
3
- * emit.js implements an Emitter class which emits events to a list of listeners. Listeners are
4
- * simply functions to call, and "emitting an event" just calls those functions.
5
- *
6
- * This is similar to Backbone events, with more focus on efficiency. Both inserting and removing
7
- * listeners is constant time.
8
- *
9
- * To create an emitter:
10
- * let emitter = new Emitter();
11
- *
12
- * To add a listener:
13
- * let listener = fooEmitter.addListener(callback);
14
- * To remove a listener:
15
- * listener.dispose();
16
- *
17
- * The only way to remove a listener is to dispose the Listener object returned by addListener().
18
- * You can often use autoDispose to do this automatically when subscribing in a constructor:
19
- * this.autoDispose(fooEmitter.addListener(this.onFoo, this));
20
- *
21
- * To emit an event, call emit() with any number of arguments:
22
- * emitter.emit("hello", "world");
23
- */
24
2
  Object.defineProperty(exports, "__esModule", { value: true });
25
- // Note about a possible alternative implementation.
26
- //
27
- // We could implement the same interface using an array of listeners. Certain issues apply, in
28
- // particular with removing listeners from inside emit(), and in ensuring that removals are
29
- // constant time on average. Such an implementation was attempted and timed. The result is that
30
- // compared to the linked-list implementation here, add/remove combination could be made nearly
31
- // twice faster (on average), while emit and add/remove/emit are consistently slightly slower.
32
- //
33
- // The implementation here was chosen based on those timings, and as the simpler one. For example,
34
- // on one setup (macbook, node4, 5-listener queue), add+remove take 0.1us, while add+remove+emit
35
- // take 3.82us. (In array-based implementation with same set up, add+remove is 0.06us, while
36
- // add+remove+emit is 4.80us.)
37
- // The private property name to hold next/prev pointers.
3
+ exports.Listener = exports.Emitter = exports.LLink = void 0;
38
4
  function _noop() { }
39
5
  /**
40
6
  * This is an implementation of a doubly-linked list, with just the minimal functionality we need.
7
+ * @internal
41
8
  */
42
9
  class LLink {
43
10
  constructor() {
@@ -66,7 +33,7 @@ class LLink {
66
33
  node._prev = node._next = null;
67
34
  }
68
35
  _disposeList() {
69
- let node = this;
36
+ let node = this; // eslint-disable-line @typescript-eslint/no-this-alias
70
37
  let next = node._next;
71
38
  while (next !== null) {
72
39
  node._next = node._prev = null;
@@ -76,20 +43,65 @@ class LLink {
76
43
  }
77
44
  }
78
45
  exports.LLink = LLink;
46
+ /**
47
+ * An `Emitter` emits events to a list of listeners. Listeners are
48
+ * simply functions to call, and "emitting an event" just calls those functions.
49
+ *
50
+ * This is similar to Backbone events, with more focus on efficiency. Both inserting and removing
51
+ * listeners is constant time.
52
+ *
53
+ * To create an emitter:
54
+ * ```ts
55
+ * const emitter = new Emitter();
56
+ * ```
57
+ *
58
+ * To add a listener:
59
+ * ```ts
60
+ * const listener = fooEmitter.addListener(callback);
61
+ * ```
62
+ *
63
+ * To remove a listener:
64
+ * ```ts
65
+ * listener.dispose();
66
+ * ```
67
+ *
68
+ * The only way to remove a listener is to dispose the `Listener` object returned by `addListener()`.
69
+ * You can often use autoDispose to do this automatically when subscribing in a constructor:
70
+ * ```ts
71
+ * this.autoDispose(fooEmitter.addListener(this.onFoo, this));
72
+ * ```
73
+ *
74
+ * To emit an event, call `emit()` with any number of arguments:
75
+ * ```ts
76
+ * emitter.emit("hello", "world");
77
+ * ```
78
+ *
79
+ * @privateRemarks
80
+ *
81
+ * Note about a possible alternative implementation.
82
+ *
83
+ * We could implement the same interface using an array of listeners. Certain issues apply, in
84
+ * particular with removing listeners from inside emit(), and in ensuring that removals are
85
+ * constant time on average. Such an implementation was attempted and timed. The result is that
86
+ * compared to the linked-list implementation here, add/remove combination could be made nearly
87
+ * twice faster (on average), while emit and add/remove/emit are consistently slightly slower.
88
+ *
89
+ * The implementation here was chosen based on those timings, and as the simpler one. For example,
90
+ * on one setup (macbook, node4, 5-listener queue), add+remove take 0.1us, while add+remove+emit
91
+ * take 3.82us. (In array-based implementation with same set up, add+remove is 0.06us, while
92
+ * add+remove+emit is 4.80us.)
93
+ */
79
94
  class Emitter extends LLink {
80
- /**
81
- * Constructs an Emitter object.
82
- */
83
95
  constructor() {
84
- super();
96
+ super(...arguments);
85
97
  this._changeCB = _noop;
86
98
  this._changeCBContext = undefined;
87
99
  }
88
100
  /**
89
101
  * Adds a listening callback to the list of functions to call on emit().
90
- * @param {Function} callback: Function to call.
91
- * @param {Object} optContext: Context for the function.
92
- * @returns {Listener} Listener object. Its dispose() method removes the callback from the list.
102
+ * @param callback - Function to call.
103
+ * @param optContext - Context for the function.
104
+ * @returns Listener object. Its dispose() method removes the callback from the list.
93
105
  */
94
106
  addListener(callback, optContext) {
95
107
  return new Listener(this, callback, optContext);
@@ -102,7 +114,7 @@ class Emitter extends LLink {
102
114
  }
103
115
  /**
104
116
  * Sets the single callback that would get called when a listener is added or removed.
105
- * @param {Function} changeCB(hasListeners): Function to call after a listener is added or
117
+ * @param changeCB - Function to call after a listener is added or
106
118
  * removed. It's called with a boolean indicating whether this Emitter has any listeners.
107
119
  * Pass in `null` to unset the callback. Note that it can be called multiple times in a row
108
120
  * with hasListeners `true`.
@@ -113,6 +125,7 @@ class Emitter extends LLink {
113
125
  }
114
126
  /**
115
127
  * Helper used by Listener class, but not intended for public usage.
128
+ * @internal
116
129
  */
117
130
  _triggerChangeCB() {
118
131
  this._changeCB.call(this._changeCBContext, this.hasListeners());
@@ -135,10 +148,18 @@ class Emitter extends LLink {
135
148
  }
136
149
  exports.Emitter = Emitter;
137
150
  /**
138
- * Listener object wraps a callback added to an Emitter, allowing for O(1) removal when the
139
- * listener is disposed.
151
+ * The `Listener` object wraps a callback added to an Emitter, allowing for O(1) removal when the
152
+ * listener is disposed. It implements `IDisposable`.
140
153
  */
141
154
  class Listener extends LLink {
155
+ /** @internal */
156
+ static callAll(begin, end, args) {
157
+ while (begin !== end) {
158
+ const lis = begin;
159
+ lis.callback.call(lis.context, ...args);
160
+ begin = lis._next;
161
+ }
162
+ }
142
163
  constructor(emitter, callback, context) {
143
164
  super();
144
165
  this.emitter = emitter;
@@ -147,13 +168,7 @@ class Listener extends LLink {
147
168
  this._insertBefore(emitter, this);
148
169
  emitter._triggerChangeCB();
149
170
  }
150
- static callAll(begin, end, args) {
151
- while (begin !== end) {
152
- const lis = begin;
153
- lis.callback.call(lis.context, ...args);
154
- begin = lis._next;
155
- }
156
- }
171
+ /** @internal */
157
172
  dispose() {
158
173
  if (this.isDisposed()) {
159
174
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../../lib/emit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAE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OAAO;SAAE;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAClC,CAAC;CACF;AAxBD,4BAwBC"}
@@ -32,7 +32,7 @@ export interface IKnockoutReadObservable<T> {
32
32
  subscribe(callback: (newValue: T) => void, target?: any, event?: "change"): any;
33
33
  getSubscriptionsCount(): number;
34
34
  }
35
- export declare type InferKoType<KObs extends IKnockoutReadObservable<any>> = KObs extends {
35
+ export type InferKoType<KObs extends IKnockoutReadObservable<any>> = KObs extends {
36
36
  peek(): infer T;
37
37
  } ? T : never;
38
38
  /**
@@ -44,18 +44,21 @@ export declare type InferKoType<KObs extends IKnockoutReadObservable<any>> = KOb
44
44
  */
45
45
  export declare function fromKo<KObs extends IKnockoutObservable<any>>(koObs: KObs): Observable<InferKoType<KObs>>;
46
46
  /**
47
- * An Observable that wraps a Knockout observable, created via fromKo(). It keeps minimal overhead
47
+ * An Observable that wraps a Knockout observable, created via `fromKo()`. It keeps minimal overhead
48
48
  * when unused by only subscribing to the wrapped observable while it itself has subscriptions.
49
49
  *
50
- * This way, when unused, the only reference is from the wrapper to the wrapped object. KoWrapObs
50
+ * This way, when unused, the only reference is from the wrapper to the wrapped object. `KoWrapObs`
51
51
  * should not be disposed; its lifetime is tied to that of the wrapped object.
52
52
  */
53
53
  export declare class KoWrapObs<T> extends Observable<T> {
54
54
  private _koObs;
55
55
  private _koSub;
56
56
  constructor(_koObs: IKnockoutObservable<T>);
57
+ /** @override */
57
58
  get(): T;
59
+ /** @override */
58
60
  set(value: T): void;
61
+ /** @override */
59
62
  dispose(): void;
60
63
  }
61
64
  export interface IKnockoutModule {
@@ -24,6 +24,7 @@
24
24
  * the returned wrapper should not be disposed; it's tied to the lifetime of the wrapped object.
25
25
  */
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.setupKoDisposal = exports.toKo = exports.KoWrapObs = exports.fromKo = void 0;
27
28
  const domDispose_1 = require("./domDispose");
28
29
  const observable_1 = require("./observable");
29
30
  const fromKoWrappers = new WeakMap();
@@ -40,10 +41,10 @@ function fromKo(koObs) {
40
41
  }
41
42
  exports.fromKo = fromKo;
42
43
  /**
43
- * An Observable that wraps a Knockout observable, created via fromKo(). It keeps minimal overhead
44
+ * An Observable that wraps a Knockout observable, created via `fromKo()`. It keeps minimal overhead
44
45
  * when unused by only subscribing to the wrapped observable while it itself has subscriptions.
45
46
  *
46
- * This way, when unused, the only reference is from the wrapper to the wrapped object. KoWrapObs
47
+ * This way, when unused, the only reference is from the wrapper to the wrapped object. `KoWrapObs`
47
48
  * should not be disposed; its lifetime is tied to that of the wrapped object.
48
49
  */
49
50
  class KoWrapObs extends observable_1.Observable {
@@ -64,8 +65,11 @@ class KoWrapObs extends observable_1.Observable {
64
65
  }
65
66
  });
66
67
  }
68
+ /** @override */
67
69
  get() { return this._koObs.peek(); }
68
- set(value) { observable_1.bundleChanges(() => this._koObs(value)); }
70
+ /** @override */
71
+ set(value) { (0, observable_1.bundleChanges)(() => this._koObs(value)); }
72
+ /** @override */
69
73
  dispose() { throw new Error("KoWrapObs should not be disposed"); }
70
74
  }
71
75
  exports.KoWrapObs = KoWrapObs;
@@ -1 +1 @@
1
- {"version":3,"file":"kowrap.js","sourceRoot":"","sources":["../../../lib/kowrap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAEH,6CAA6C;AAC7C,6CAAuD;AA0BvD,MAAM,cAAc,GAAuD,IAAI,OAAO,EAAE,CAAC;AACzF,MAAM,YAAY,GAAuD,IAAI,OAAO,EAAE,CAAC;AAEvF;;;;;;GAMG;AACH,SAAgB,MAAM,CAAwC,KAAW;IACvE,OAAO,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC;AAClG,C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AAC;IAEpE,yFAAyF;IACzF,MAAM,yBAAyB,GAAG,4BAAe,CAAC,gBAAgB,CAAC;IAEnE,8FAA8F;IAC9F,2DAA2D;IAC3D,SAAS,sBAAsB,CAAC,IAAU;QACxC,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAC9B,4BAAe,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,2FAA2F;IAC3F,4FAA4F;IAC5F,kBAAkB;IAClB,SAAS,wBAAwB,CAAC,IAAU;QAC1C,yBAAyB,CAAC,IAAI,CAAC,CAAC;QAEhC,6FAA6F;QAC7F,0CAA0C;QAC1C,iBAAiB,CAAC,iBAAiB,GAAG,uBAAuB,CAAC;QAC9D,IAAI;YACF,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACpB;gBAAS;YACR,iBAAiB,CAAC,iBAAiB,GAAG,sBAAsB,CAAC;SAC9D;IACH,CAAC;IAED,4EAA4E;IAC5E,iBAAiB,CAAC,iBAAiB,GAAG,sBAAsB,CAAC;IAC7D,4BAAe,CAAC,gBAAgB,GAAG,wBAAwB,CAAC;AAC9D,CAAC;AAxCD,0CAwCC"}
@@ -1,35 +1,3 @@
1
- /**
2
- * ObsArray extends a plain Observable to allow for more efficient observation of array changes.
3
- *
4
- * As for any array-valued Observable, when the contents of the observed array changes, the
5
- * listeners get called with new and previous values which are the same array. For simple changes,
6
- * such as those made with .push() and .splice() methods, ObsArray allows for more efficient
7
- * handling of the change by calling listeners with splice info in the third argument.
8
- *
9
- * This module also provides computedArray(), which allows mapping each item of an ObsArray
10
- * through a function, passing through splice info for efficient handling of small changes. It
11
- * also allows mapping an observable or a computed whose value is an ObsArray.
12
- *
13
- * There is no need or benefit in using computedArray() if you have a computed() that returns a
14
- * plain array. It is specifically for the case when you want to preserve the efficiency of
15
- * ObsArray when you map its values.
16
- *
17
- * Both ObsArray and ComputedArray may be used with disposable elements as their owners. E.g.
18
- *
19
- * const arr = obsArray<D>();
20
- * arr.push(D.create(arr, "x"), D.create(arr, "y"));
21
- * arr.pop(); // Element "y" gets disposed.
22
- * arr.dispose(); // Element "x" gets disposed.
23
- *
24
- * const values = obsArray<string>();
25
- * const compArr = computedArray<D>(values, (val, i, compArr) => D.create(compArr, val));
26
- * values.push("foo", "bar"); // D("foo") and D("bar") get created
27
- * values.pop(); // D("bar") gets disposed.
28
- * compArr.dispose(); // D("foo") gets disposed.
29
- *
30
- * Note that only the pattern above works: obsArray (or compArray) may only be used to take
31
- * ownership of those disposables that are added to it as array elements.
32
- */
33
1
  import { IDisposable, IDisposableOwnerT } from './dispose';
34
2
  import { Listener } from './emit';
35
3
  import { BaseObservable, Observable } from './observable';
@@ -37,49 +5,85 @@ import { BaseObservable, Observable } from './observable';
37
5
  * Either an observable or a plain array of T. This is useful for functions like dom.forEach()
38
6
  * which are convenient to have available for both.
39
7
  */
40
- export declare type MaybeObsArray<T> = BaseObservable<T[]> | T[];
8
+ export type MaybeObsArray<T> = BaseObservable<T[]> | T[];
41
9
  /**
42
10
  * Info about a modification to ObsArray contents. It is included as a third argument to change
43
11
  * listeners when available. When not available, listeners should assume that the array changed
44
12
  * completely.
45
13
  */
46
14
  export interface IObsArraySplice<T> {
47
- start: number;
15
+ start: number; /** asdf */
48
16
  numAdded: number;
49
17
  deleted: T[];
50
18
  }
51
- export declare type ISpliceListener<T, C> = (this: C, val: T[], prev: T[], change?: IObsArraySplice<T>) => void;
19
+ export type ISpliceListener<T, C> = (this: C, val: T[], prev: T[], change?: IObsArraySplice<T>) => void;
52
20
  /**
53
- * ObsArray<T> is essentially an array-valued observable. The main difference is that it may be
21
+ * `ObsArray<T>` is essentially an array-valued observable. It extends a plain Observable to allow
22
+ * for more efficient observation of array changes. It also may be
54
23
  * used as an owner for disposable array elements.
24
+ *
25
+ * As for any array-valued `Observable`, when the contents of the observed array changes, the
26
+ * listeners get called with new and previous values which are the same array. For simple changes,
27
+ * such as those made with `.push()` and `.splice()` methods, `ObsArray` allows for more efficient
28
+ * handling of the change by calling listeners with splice info in the third argument.
29
+ *
30
+ * `ObsArray` may be used with disposable elements as their owner. E.g.
31
+ * ```ts
32
+ * const arr = obsArray<D>();
33
+ * arr.push(D.create(arr, "x"), D.create(arr, "y"));
34
+ * arr.pop(); // Element "y" gets disposed.
35
+ * arr.dispose(); // Element "x" gets disposed.
36
+ * ```
37
+ *
38
+ * Note that only the pattern above works: `obsArray` may only be used to take
39
+ * ownership of those disposables that are added to it as array elements.
55
40
  */
56
41
  export declare class ObsArray<T> extends BaseObservable<T[]> {
57
42
  private _ownedItems?;
43
+ /**
44
+ * Adds a callback to listen to changes in the observable. In case of `ObsArray`, the listener
45
+ * gets additional information.
46
+ */
58
47
  addListener(callback: ISpliceListener<T, void>): Listener;
59
48
  addListener<C>(callback: ISpliceListener<T, C>, context: C): Listener;
49
+ /**
50
+ * Take ownership of an item added to this array. This should _only_ be used for array elements,
51
+ * not any unrelated items.
52
+ */
60
53
  autoDispose(value: T & IDisposable): T & IDisposable;
54
+ /** @override */
61
55
  dispose(): void;
56
+ /** @internal */
62
57
  protected _setWithSplice(value: T[], splice: IObsArraySplice<T>): void;
58
+ /** @internal */
63
59
  protected _disposeOwned(splice?: IObsArraySplice<T>): void;
64
60
  }
65
61
  /**
66
- * MutableObsArray<T> adds array-like mutation methods which emit events with splice info, to
67
- * allow more efficient processing of such changes. It is created with obsArray<T>().
62
+ * `MutableObsArray<T>` adds array-like mutation methods which emit events with splice info, to
63
+ * allow more efficient processing of such changes. It is created with `obsArray<T>()`.
68
64
  */
69
65
  export declare class MutableObsArray<T> extends ObsArray<T> {
66
+ /** Appends elements to the end and returns the new length (like `Array#push`). */
70
67
  push(...args: T[]): number;
68
+ /** Removes and returns the last element (like `Array#pop`). */
71
69
  pop(): T | undefined;
70
+ /** Prepends elements to the start and returns the new length (like `Array#unshift`). */
72
71
  unshift(...args: T[]): number;
72
+ /** Removes and returns the first element (like `Array#shift`). */
73
73
  shift(): T | undefined;
74
+ /**
75
+ * Removes and/or inserts elements at a given index and returns the removed elements (like
76
+ * `Array#splice`).
77
+ */
74
78
  splice(start: number, deleteCount?: number, ...newValues: T[]): T[];
75
79
  }
76
80
  /**
77
81
  * Creates a new MutableObsArray with an optional initial value, defaulting to the empty array.
78
- * It is essentially the same as observable<T[]>, but with array-like mutation methods.
82
+ * It is essentially the same as `observable<T[]>`, but with array-like mutation methods.
79
83
  */
80
84
  export declare function obsArray<T>(value?: T[]): MutableObsArray<T>;
81
85
  /**
82
- * See computedArray() below for documentation.
86
+ * See [`computedArray()`](#computedArray) for documentation.
83
87
  */
84
88
  export declare class ComputedArray<T, U> extends ObsArray<U> {
85
89
  private _mapper;
@@ -88,6 +92,7 @@ export declare class ComputedArray<T, U> extends ObsArray<U> {
88
92
  private _listener?;
89
93
  private _lastSplice?;
90
94
  constructor(obsArr: BaseObservable<T[]> | Observable<BaseObservable<T[]>>, _mapper: (item: T, index: number, arr: ComputedArray<T, U>) => U);
95
+ /** @internal */
91
96
  dispose(): void;
92
97
  private _syncMap;
93
98
  private _unsync;
@@ -96,25 +101,43 @@ export declare class ComputedArray<T, U> extends ObsArray<U> {
96
101
  private _recordChange;
97
102
  }
98
103
  /**
99
- * Returns an ObsArray that maps all elements of the passed-in ObsArray through a mapper function.
100
- * Also accepts an observable (e.g. a computed) whose value is an ObsArray. Usage:
101
- *
102
- * computedArray(obsArray, mapper)
103
- *
104
- * The result is entirely analogous to:
104
+ * Returns an `ObsArray` that maps all elements of the passed-in `ObsArray` through a mapper
105
+ * function. Also accepts an observable (e.g. a computed) whose value is an `ObsArray`.
106
+ * ```ts
107
+ * computedArray(obsArray, mapper)
108
+ * ```
105
109
  *
106
- * computed((use) => use(obsArray).map(mapper)) // for ObsArray
107
- * computed((use) => use(use(obsArray)).map(mapper)) // for Observable<ObsArray>
110
+ * The result is analogous to:
111
+ * ```ts
112
+ * computed((use) => use(obsArray).map(mapper)) // for ObsArray
113
+ * computed((use) => use(use(obsArray)).map(mapper)) // for Observable<ObsArray>
114
+ * ```
108
115
  *
109
- * The benefit of computedArray() is that a small change to the source array (e.g. one item
116
+ * The benefit of `computedArray()` is that a small change to the source array (e.g. one item
110
117
  * added or removed), causes a small change to the mapped array, rather than a full rebuild.
111
118
  *
112
- * This is useful with an ObsArray or with an observable whose value is an ObsArray, and also
113
- * when the computed array owns its disposable items.
119
+ * This is useful with an `ObsArray` or with an observable whose value is an `ObsArray`, and also
120
+ * when the computed array's items are disposable and it owns them.
114
121
  *
115
- * Note that the mapper function is called with (item, index, array) as for a standard
116
- * array.map(), but that the index is only accurate at the time of the call, and will stop
122
+ * There is no need or benefit to using `computedArray()` if you have a `computed()` that returns
123
+ * a plain array. It is specifically for the case when you want to preserve the efficiency of
124
+ * `ObsArray` when you map its values.
125
+ *
126
+ * Note that the mapper function is called with `(item, index, array)` as for a standard
127
+ * `array.map()`, but that the index is only accurate at the time of the call, and will stop
117
128
  * reflecting the true index if more items are inserted into the array later.
129
+ *
130
+ * As with `ObsArray`, a `ComputedArray` may be used with disposable elements as their owners. E.g.
131
+ * ```ts
132
+ * const values = obsArray<string>();
133
+ * const compArr = computedArray<D>(values, (val, i, compArr) => D.create(compArr, val));
134
+ * values.push("foo", "bar"); // D("foo") and D("bar") get created
135
+ * values.pop(); // D("bar") gets disposed.
136
+ * compArr.dispose(); // D("foo") gets disposed.
137
+ * ```
138
+ *
139
+ * Note that only the pattern above works: obsArray (or compArray) may only be used to take
140
+ * ownership of those disposables that are added to it as array elements.
118
141
  */
119
142
  export declare function computedArray<T, U>(obsArr: BaseObservable<T[]> | Observable<BaseObservable<T[]>>, mapper: (item: T, index: number, arr: ComputedArray<T, U>) => U): ObsArray<U>;
120
143
  /**
@@ -128,13 +151,28 @@ export declare function computedArray<T, U>(obsArr: BaseObservable<T[]> | Observ
128
151
  * observable will not be adjusted as the array changes, except to keep it valid.
129
152
  */
130
153
  export declare function makeLiveIndex<T>(owner: IDisposableOwnerT<LiveIndex> | null, obsArr: ObsArray<T>, initialIndex?: number): LiveIndex;
154
+ /**
155
+ * An Observable that represents an index into an `ObsArray`, clamped to be in the valid range.
156
+ */
131
157
  export declare class LiveIndex extends Observable<number | null> {
132
158
  private _obsArray;
133
159
  private _listener;
134
160
  private _isLive;
135
161
  constructor(_obsArray: ObsArray<any>, initialIndex?: number);
162
+ /**
163
+ * Set the index, clamping it to a valid value.
164
+ */
136
165
  set(index: number | null): void;
166
+ /**
167
+ * Turn "liveness" on or off. While set to false, the observable will not be adjusted as the
168
+ * array changes, except to keep it valid.
169
+ *
170
+ * @privateRemarks
171
+ * Note that this feature comes from a rather obscure need, and it would be better if something
172
+ * similar were possible without making it an explicit feature.
173
+ */
137
174
  setLive(value: boolean): void;
175
+ /** @override */
138
176
  dispose(): void;
139
177
  private _onArrayChange;
140
178
  }