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,102 +1,94 @@
1
+ import { LLink } from './emit';
2
+ // Internal "owner" of disposable objects which doesn't actually dispose or keep track of them. It
3
+ // is the effective owner when creating a Disposable with `new Foo()` rather than `Foo.create()`.
4
+ const _noopOwner = {
5
+ autoDispose(obj) { },
6
+ };
7
+ // Newly-created Disposable instances will have this as their owner. This is not a constant, it
8
+ // is used by create() for the safe creation of Disposables.
9
+ let _defaultDisposableOwner = _noopOwner;
1
10
  /**
2
- * dispose.js provides tools to objects that needs to dispose resources, such as destroy DOM, and
3
- * unsubscribe from events. The motivation with examples is presented here:
11
+ * Base class for disposable objects that can own other objects.
4
12
  *
5
- * https://phab.getgrist.com/w/disposal/
13
+ * For background and motivation, see [Disposables](/dispose).
6
14
  *
7
- * Disposable is a class for components that need cleanup (e.g. maintain DOM, listen to events,
8
- * subscribe to anything). It provides a .dispose() method that should be called to destroy the
9
- * component, and .onDispose()/.autoDispose() methods that the component should use to take
15
+ * `Disposable` is a class for components that need cleanup (e.g. maintain DOM, listen to events,
16
+ * subscribe to anything). It provides a `.dispose()` method that should be called to destroy the
17
+ * component, and `.onDispose()` / `.autoDispose()` methods that the component should use to take
10
18
  * responsibility for other pieces that require cleanup.
11
19
  *
12
20
  * To define a disposable class:
13
- * class Foo extends Disposable { ... }
21
+ * ```ts
22
+ * class Foo extends Disposable { ... }
23
+ * ```
14
24
  *
15
- * To create Foo:
16
- * const foo = Foo.create(owner, ...args);
25
+ * To create `Foo`:
26
+ * ```ts
27
+ * const foo = Foo.create(owner, ...args);
28
+ * ```
17
29
  * This is better than `new Foo` for two reasons:
18
- * 1. If Foo's constructor throws an exception, any disposals registered in that constructor
30
+ * 1. If `Foo`'s constructor throws an exception, any disposals registered in that constructor
19
31
  * before the exception are honored.
20
32
  * 2. It ensures you specify the owner of the new instance (but you can use null to skip it).
21
33
  *
22
- * In Foo's constructor (or rarely methods), take ownership of other Disposable objects:
23
- * this.bar = Bar.create(this, ...);
34
+ * In `Foo`'s constructor (or rarely methods), take ownership of other Disposable objects:
35
+ * ```ts
36
+ * this.bar = Bar.create(this, ...);
37
+ * ```
24
38
  *
25
39
  * For objects that are not instances of Disposable but have a .dispose() methods, use:
26
- * this.bar = this.autoDispose(createSomethingDisposable());
40
+ * ```ts
41
+ * this.bar = this.autoDispose(createSomethingDisposable());
42
+ * ```
27
43
  *
28
44
  * To call a function on disposal (e.g. to add custom disposal logic):
29
- * this.onDispose(() => this.myUnsubscribeAllMethod());
30
- * this.onDispose(this.myUnsubscribeAllMethod, this); // slightly more efficient
45
+ * ```ts
46
+ * this.onDispose(() => this.myUnsubscribeAllMethod());
47
+ * this.onDispose(this.myUnsubscribeAllMethod, this);
48
+ * ```
31
49
  *
32
50
  * To mark this object to be wiped out on disposal (i.e. set all properties to null):
33
- * this.wipeOnDispose();
51
+ * ```ts
52
+ * this.wipeOnDispose();
53
+ * ```
34
54
  * See the documentation of that method for more info.
35
55
  *
36
- * To dispose Foo directly:
37
- * foo.dispose();
38
- * To determine if an object has already been disposed:
39
- * foo.isDisposed()
56
+ * To dispose Foo directly: `foo.dispose()`.
40
57
  *
41
- * If you need to replace an owned object, or release, or dispose it early, use a Holder:
42
- * this._holder = Holder.create(this);
43
- * Bar.create(this._holder, 1); // creates new Bar(1)
44
- * Bar.create(this._holder, 2); // creates new Bar(2) and disposes previous object
45
- * this._holder.clear(); // disposes contained object
46
- * this._holder.release(); // releases contained object
58
+ * To determine if an object has already been disposed: `foo.isDisposed()`.
47
59
  *
48
- * If you need a container for multiple objects and dispose them all together, use a MultiHolder:
49
- * this._mholder = MultiHolder.create(null);
50
- * Bar.create(this._mholder, 1); // create new Bar(1)
51
- * Bar.create(this._mholder, 2); // create new Bar(2)
52
- * this._mholder.dispose(); // disposes both objects
60
+ * If you need to replace an owned object, or release, or dispose it early, use a
61
+ * [`Holder`](#Holder) or [`MultiHolder`](#MultiHolder).
53
62
  *
54
- * If creating your own class with a dispose() method, do NOT throw exceptions from dispose().
55
- * These cannot be handled properly in all cases. Read here about the same issue in C++:
56
- * http://bin-login.name/ftp/pub/docs/programming_languages/cpp/cffective_cpp/MAGAZINE/SU_FRAME.HTM#destruct
63
+ * If creating your own class with a `dispose()` method, do NOT throw exceptions from `dispose()`.
64
+ * These cannot be handled properly in all cases.
57
65
  *
58
66
  * Using a parametrized (generic) class as a Disposable is tricky. E.g.
59
- * class Bar<T> extends Disposable { ... }
60
- * // Bar<T>.create(...) <-- doesn't work
61
- * // Bar.create<T>(...) <-- doesn't work
62
- * // Bar.create(...) <-- works, but with {} for Bar's type parameters
67
+ * ```ts
68
+ * class Bar<T> extends Disposable { ... }
69
+ * // Bar<T>.create(...) <-- doesn't work
70
+ * // Bar.create<T>(...) <-- doesn't work
71
+ * // Bar.create(...) <-- works, but with {} for Bar's type parameters
72
+ * ```
63
73
  *
64
74
  * The solution is to expose the constructor type using a helper method:
65
- * class Bar<T> extends Disposable {
66
- * // Note the tuple below which must match the constructor parameters of Bar<U>.
67
- * public static ctor<U>(): IDisposableCtor<Bar<U>, [U, boolean]> { return this; }
68
- * constructor(a: T, b: boolean) { ... }
69
- * }
70
- * Bar.ctor<T>().create(...) // <-- works, creates Bar<T>, and does type-checking!
71
- */
72
- import { LLink } from './emit';
73
- // Internal "owner" of disposable objects which doesn't actually dispose or keep track of them. It
74
- // is the effective owner when creating a Disposable with `new Foo()` rather than `Foo.create()`.
75
- const _noopOwner = {
76
- autoDispose(obj) { },
77
- };
78
- // Newly-created Disposable instances will have this as their owner. This is not a constant, it
79
- // is used by create() for the safe creation of Disposables.
80
- let _defaultDisposableOwner = _noopOwner;
81
- /**
82
- * Base class for disposable objects that can own other objects. See the module documentation.
75
+ * ```ts
76
+ * class Bar<T> extends Disposable {
77
+ * // Note the tuple below which must match the constructor parameters of Bar<U>.
78
+ * public static ctor<U>(): IDisposableCtor<Bar<U>, [U, boolean]> { return this; }
79
+ * constructor(a: T, b: boolean) { ... }
80
+ * }
81
+ * Bar.ctor<T>().create(...) // <-- works, creates Bar<T>, and does type-checking!
82
+ * ```
83
83
  */
84
84
  export class Disposable {
85
- constructor() {
86
- this._disposalList = new DisposalList();
87
- // This registers with a temp Holder when using create(), and is a no-op when using `new Foo`.
88
- _defaultDisposableOwner.autoDispose(this);
89
- // Be sure to reset to no-op, so that a (non-recommended) direct call like 'new Bar()', from
90
- // inside Foo's constructor doesn't use the same Holder that's temporarily holding Foo.
91
- _defaultDisposableOwner = _noopOwner;
92
- }
93
85
  /**
94
86
  * Create Disposable instances using `Class.create(owner, ...)` rather than `new Class(...)`.
95
87
  *
96
88
  * This reminds you to provide an owner, and ensures that if the constructor throws an
97
- * exception, dispose() gets called to clean up the partially-constructed object.
89
+ * exception, `dispose()` gets called to clean up the partially-constructed object.
98
90
  *
99
- * Owner may be null if intend to ensure disposal some other way.
91
+ * Owner may be `null` if you intend to ensure disposal some other way.
100
92
  */
101
93
  static create(owner, ...args) {
102
94
  const origDefaultOwner = _defaultDisposableOwner;
@@ -124,12 +116,20 @@ export class Disposable {
124
116
  _defaultDisposableOwner = origDefaultOwner;
125
117
  }
126
118
  }
127
- /** Take ownership of obj, and dispose it when this.dispose() is called. */
119
+ constructor() {
120
+ this._disposalList = new DisposalList();
121
+ // This registers with a temp Holder when using create(), and is a no-op when using `new Foo`.
122
+ _defaultDisposableOwner.autoDispose(this);
123
+ // Be sure to reset to no-op, so that a (non-recommended) direct call like 'new Bar()', from
124
+ // inside Foo's constructor doesn't use the same Holder that's temporarily holding Foo.
125
+ _defaultDisposableOwner = _noopOwner;
126
+ }
127
+ /** Take ownership of `obj`, and dispose it when `this.dispose()` is called. */
128
128
  autoDispose(obj) {
129
129
  this.onDispose(obj.dispose, obj);
130
130
  return obj;
131
131
  }
132
- /** Call the given callback when this.dispose() is called. */
132
+ /** Call the given callback when `this.dispose()` is called. */
133
133
  onDispose(callback, context) {
134
134
  return this._disposalList.addListener(callback, context);
135
135
  }
@@ -138,10 +138,13 @@ export class Disposable {
138
138
  * recommended to call this early in the constructor.
139
139
  *
140
140
  * This makes disposal more costly, but has certain benefits:
141
+ *
141
142
  * - If anything still refers to the object and uses it, we'll get an early error, rather than
142
143
  * silently keep going, potentially doing useless work (or worse) and wasting resources.
144
+ *
143
145
  * - If anything still refers to the object (even without using it), the fields of the object
144
146
  * can still be garbage-collected.
147
+ *
145
148
  * - If there are circular references involving this object, they get broken, making the job
146
149
  * easier for the garbage collector.
147
150
  *
@@ -158,7 +161,7 @@ export class Disposable {
158
161
  return this._disposalList === null;
159
162
  }
160
163
  /**
161
- * Clean up `this` by disposing all owned objects, and calling onDispose() callbacks, in reverse
164
+ * Clean up `this` by disposing all owned objects, and calling `onDispose()` callbacks, in reverse
162
165
  * order to that in which they were added.
163
166
  */
164
167
  dispose() {
@@ -187,17 +190,31 @@ export class Disposable {
187
190
  }
188
191
  /**
189
192
  * Holder keeps a single disposable object. If given responsibility for another object using
190
- * holder.autoDispose() or Foo.create(holder, ...), it automatically disposes the currently held
193
+ * `holder.autoDispose()` or `Foo.create(holder, ...)`, it automatically disposes the currently held
191
194
  * object. It also disposes it when the holder itself is disposed.
192
195
  *
193
- * If the object is an instance of Disposable, the holder will also notice when the object gets
196
+ * If the object is an instance of `Disposable`, the holder will also notice when the object gets
194
197
  * disposed from outside of it, in which case the holder will become empty again.
198
+ *
199
+ * If you need a container for multiple objects and dispose them all together, use a `MultiHolder`:
200
+ *
201
+ * :::info Example
202
+ * ```ts
203
+ * this._holder = Holder.create(this);
204
+ * Bar.create(this._holder, 1); // creates new Bar(1), assuming it's a Disposable
205
+ * Bar.create(this._holder, 2); // creates new Bar(2) and disposes previous object
206
+ * this._holder.clear(); // disposes contained object
207
+ * this._holder.release(); // releases contained object
208
+ * ```
209
+ * :::
195
210
  */
196
211
  export class Holder {
197
212
  constructor() {
213
+ /** @internal */
198
214
  this._owned = null;
199
215
  this._disposalListener = undefined;
200
216
  }
217
+ /** `Holder.create(owner)` creates a new `Holder`. */
201
218
  static create(owner) {
202
219
  return setDisposeOwner(owner, new Holder());
203
220
  }
@@ -246,9 +263,18 @@ export class Holder {
246
263
  }
247
264
  }
248
265
  /**
249
- * MultiHolder keeps multiple disposable object. It disposes all held object when the holder
250
- * itself is disposed. It's actually nothing more than the Disposable base class itself, just
266
+ * `MultiHolder` keeps multiple disposable objects. It disposes all held object when the holder
267
+ * itself is disposed. It's actually nothing more than the `Disposable` base class itself, just
251
268
  * exposed with a clearer name that describes its purpose.
269
+ *
270
+ * :::info Example
271
+ * ```ts
272
+ * this._mholder = MultiHolder.create(null);
273
+ * Bar.create(this._mholder, 1); // create new Bar(1)
274
+ * Bar.create(this._mholder, 2); // create new Bar(2)
275
+ * this._mholder.dispose(); // disposes both objects
276
+ * ```
277
+ * :::
252
278
  */
253
279
  export class MultiHolder extends Disposable {
254
280
  }
@@ -296,11 +322,6 @@ class DisposalList extends LLink {
296
322
  * reports and swallows erros when it calls the callbacks in the list.
297
323
  */
298
324
  class DisposeListener extends LLink {
299
- constructor(callback, context) {
300
- super();
301
- this.callback = callback;
302
- this.context = context;
303
- }
304
325
  static callAll(begin, end, owner) {
305
326
  while (begin !== end) {
306
327
  const lis = begin;
@@ -314,6 +335,11 @@ class DisposeListener extends LLink {
314
335
  begin = lis._next;
315
336
  }
316
337
  }
338
+ constructor(callback, context) {
339
+ super();
340
+ this.callback = callback;
341
+ this.context = context;
342
+ }
317
343
  dispose() {
318
344
  if (this.isDisposed()) {
319
345
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"dispose.js","sourceRoot":"","sources":["../../../lib/dispose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAC;AAwB7B,kGAAkG;AAClG,iGAAiG;AACjG,MAAM,UAAU,GAAqB;IACnC,WAAW,CAAC,GAAgB,IAAqB,CAAC;CACnD,CAAC;AAEF,+FAA+F;AAC/F,4DAA4D;AAC5D,IAAI,uBAAuB,GAAG,UAAU,CAAC;AAWzC;;GAEG;AACH,MAAM,OAAgB,UAAU;IAqC9B;QAFQ,kBAAa,GAAiB,IAAI,YAAY,EAAE,CAAC;QAGvD,8FAA8F;QAC9F,uBAAuB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC1C,4FAA4F;QAC5F,uFAAuF;QACvF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C,YAAY,EAAE,CAAC;SACrB;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,eAAgB,SAAQ,KAAK;IAC1B,MAAM,CAAC,OAAO,CAAC,KAAY,EAAE,GAAU,EAAE,KAAiB;QAC/D,OAAO,KAAK,KAAK,GAAG,EAAE;YACpB,MAAM,GAAG,GAAG,KAAwB,CAAC;YACrC,IAAI;gBACF,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;aAChC;YAAC,OAAO,CAAC,EAAE;gBACV,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aACnG;YACD,KAAK,GAAG,GAAG,CAAC,KAAM,CAAC;SACpB;IACH,CAAC;IAED,YAAoB,QAAoB,EAAU,OAAa;QAAI,KAAK,EAAE,CAAC;QAAvD,aAAQ,GAAR,QAAQ,CAAY;QAAU,YAAO,GAAP,OAAO,CAAM;IAAa,CAAC;IAEtE,OAAO;QACZ,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE;YAAE,OAAO;SAAE;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CACF"}
@@ -1,21 +1,3 @@
1
- /**
2
- * dom.js provides a way to build a DOM tree easily.
3
- *
4
- * E.g.
5
- * import {dom} from 'grainjs';
6
- * dom('a#link.c1.c2', {'href': url}, 'Hello ', dom('span', 'world'));
7
- * creates Node <a id="link" class="c1 c2" href={{url}}Hello <span>world</span></a>.
8
- *
9
- * dom.frag(dom('span', 'Hello'), ['blah', dom('div', 'world')])
10
- * creates document fragment with <span>Hello</span>blah<div>world</div>.
11
- *
12
- * DOM can also be created and modified inline during creation:
13
- * dom('a#id.c1',
14
- * dom.cls('c2'), dom.attr('href', url),
15
- * dom.text('Hello '), dom('span', dom.text('world')))
16
- * creates Node <a id="link" class="c1 c2" href={{url}}Hello <span>world</span></a>,
17
- * identical to the first example above.
18
- */
19
1
  // We keep various dom-related functions organized in private modules, but they are exposed here.
20
2
  export * from './domImpl';
21
3
  export * from './domComponent';
@@ -32,6 +14,44 @@ import * as _domImpl from './domImpl';
32
14
  import * as _domMethods from './domMethods';
33
15
  import * as domevent from './domevent';
34
16
  import { dom as _dom } from './domImpl';
17
+ /**
18
+ * `dom()` provides a way to build a DOM tree easily.
19
+ *
20
+ * The first argument is a string consisting of a lowercase tag name (e.g. `"div"`), with optional
21
+ * `"#foo"` suffix to add the ID `'foo'`, and zero or more `".bar"` suffixes to add a CSS class
22
+ * `'bar'`.
23
+ *
24
+ * The rest of the arguments are optional and may be any number, of these types:
25
+ *
26
+ * @param Nodes - become children of the created element
27
+ * @param strings - become text node children
28
+ * @param objects - Literal objects to set string attributes on the element.
29
+ * E.g. `{title: "foo"}`.
30
+ * @param null - The values `null` and `undefined` values are ignored completely.
31
+ * @param Arrays - flattened with each item processed recursively
32
+ * @param functions - called with the element being built as the argument, for a chance to modify
33
+ * the element as it's being created. Return values are processed recursively.
34
+ * @param functions - "dom methods" are a expressions such as `dom.attr('href', url)` or
35
+ * `dom.hide(obs)`, which are special cases of the "functions" category.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import {dom} from 'grainjs';
40
+ * dom('a', {href: url, className: 'myclass'}, 'Hello ', dom('strong', 'world'));
41
+ * ```
42
+ * creates HTML element `<a href={{url}} class="myclass">Hello <strong>world</strong></a>`.
43
+ *
44
+ * @example
45
+ * Here's an example equivalent to the one above, using dom methods `dom.cls`, `dom.attr`,
46
+ * `dom.text`. In reality, these methods are useful with observable values rather than constant
47
+ * strings.
48
+ * ```ts
49
+ * dom('a', dom.attr('href', url), dom.cls('myclass'),
50
+ * dom.text('Hello '), dom('strong', dom.text('world')));
51
+ * ```
52
+ *
53
+ * @see [DOM & Observables](/basics).
54
+ */
35
55
  // We just want to re-export _domImpl.dom, but to allow adding methods to it in a typesafe way,
36
56
  // TypeScript wants us to declare a real function in the same file.
37
57
  export function dom(tagString, ...args) {
@@ -73,7 +93,9 @@ export function dom(tagString, ...args) {
73
93
  dom.getData = _domMethods.getData;
74
94
  dom.replaceContent = _domComputed.replaceContent;
75
95
  dom.domComputed = _domComputed.domComputed;
96
+ dom.domComputedOwned = _domComputed.domComputedOwned;
76
97
  dom.maybe = _domComputed.maybe;
98
+ dom.maybeOwned = _domComputed.maybeOwned;
77
99
  dom.forEach = _domForEach.forEach;
78
100
  dom.create = _domComponent.create;
79
101
  dom.onElem = domevent.onElem;
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../lib/dom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,iGAAiG;AACjG,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAC,GAAG,IAAI,IAAI,EAA6B,MAAM,WAAW,CAAC;AAElE,+FAA+F;AAC/F,mEAAmE;AACnE,MAAM,UAAU,GAAG,CAAsB,SAAc,EAAE,GAAG,IAA4B;IACtF,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,mEAAmE;AACnE,WAAiB,GAAG;IACL,OAAG,GAAe,Q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om().
3
+ * UI components that can be inserted into `dom()`.
3
4
  *
4
- * Components are created and inserted using dom.create():
5
+ * Components are created and inserted using `dom.create()`:
6
+ * ```ts
7
+ * dom('div',
8
+ * dom.create(MyWidget, ...myArgs), // Calls MyWidget.create(owner, ...myArgs)
9
+ * dom.create(createMyWidget, ...myArgs), // Calls createMyWidget(owner, ...myArgs)
10
+ * )
11
+ * ```
5
12
  *
6
- * dom('div',
7
- * dom.create(MyWidget, ...myArgs), // Calls MyWidget.create(owner, ...myArgs)
8
- * dom.create(createMyWidget, ...myArgs), // Calls createMyWidget(owner, ...myArgs)
9
- * )
10
- *
11
- * The first argument may be a function, which is called directly, or a class with a .create()
13
+ * The first argument may be a function, which is called directly, or a class with a `.create()`
12
14
  * static method, in which case that's what gets called.
13
15
  *
14
16
  * In both cases, the call gets a first argument of `owner` followed by the rest of the arguments
15
- * to dom.create(). The `owner` is a MultiHolder that will own this component. This works
17
+ * to `dom.create()`. The `owner` is a `MultiHolder` that will own this component. This works
16
18
  * naturally with any class that derives from Disposable, since it then has a suitable static
17
- * create() method.
19
+ * `create()` method.
18
20
  *
19
21
  * Function-based components may use owner to easily handle disposal. For example:
20
- *
21
- * dom.create(createMyWidget)
22
- * function createMyWidget(owner) {
23
- * const foo = Foo.create(owner);
24
- * return dom('div', foo.getTitle());
25
- * }
26
- *
27
- * The `owner` argument is the main benefit of dom.create(). Logically, the owner is the DOM where
22
+ * ```ts
23
+ * dom.create(createMyWidget)
24
+ * function createMyWidget(owner) {
25
+ * const foo = Foo.create(owner);
26
+ * return dom('div', foo.getTitle());
27
+ * }
28
+ * ```
29
+ *
30
+ * The `owner` argument is the main benefit of `dom.create()`. Logically, the owner is the DOM where
28
31
  * the component is attached. When the parent DOM element is disposed, so is the component.
29
32
  *
30
- * [Explanation] To understand why the syntax is such, consider a potential alternative such as:
33
+ * :::info Explanation
31
34
  *
32
- * dom('div', _insert_(new Comp1()), _insert_(new Comp2(...args)))
35
+ * To understand why the syntax is such, consider a potential alternative such as:
36
+ * ```ts
37
+ * dom('div', _insert_(new Comp1()), _insert_(new Comp2(...args)))
38
+ * ```
33
39
  *
34
- * In both cases, the constructor for Comp1 runs before the constructor for Comp2. What happens
35
- * when Comp2's constructor throws an exception? In the second case, nothing yet owns the
36
- * created Comp1 component, and it will never get cleaned up. With dom.create(), the DOM
37
- * gets ownership of Comp1 early enough and will dispose it.
40
+ * In both cases, the constructor for Comp1 runs before the constructor for Comp2. What happens
41
+ * when Comp2's constructor throws an exception? In the second case, nothing yet owns the
42
+ * created Comp1 component, and it will never get cleaned up. With `dom.create()`, the DOM
43
+ * gets ownership of Comp1 early enough and will dispose it.
44
+ *
45
+ * :::
38
46
  *
39
47
  * A function component may return DOM directly. A class component returns the class instance,
40
- * which must have a .buildDom() method which will be called right after the constructor to get
48
+ * which must have a `.buildDom()` method which will be called right after the constructor to get
41
49
  * the DOM. Note that buildDom is only called once.
42
50
  *
43
- * A function component may also return an object with .buildDom(). So these are equivalent:
44
- *
45
- * dom.create(MyWidget)
46
- * dom.create((owner) => MyWidget.create(owner))
51
+ * A function component may also return an object with `.buildDom()`. So these are equivalent:
52
+ * ```ts
53
+ * dom.create(MyWidget)
54
+ * dom.create((owner) => MyWidget.create(owner))
55
+ * ```
47
56
  *
48
57
  * Note that ownership should be handled using the `owner` argument. Don't do this:
58
+ * ```ts
59
+ * // NON-EXAMPLE: Nothing will dispose the created object:
60
+ * // dom.create(() => new MyWidget());
61
+ * ```
49
62
  *
50
- * // NON-EXAMPLE: Nothing will dispose the created object:
51
- * // dom.create(() => new MyWidget());
52
- *
53
- * The returned DOM may includes Nodes, strings, and domComputed() values, as well as arrays of
54
- * any of these. In other words, any DomArg goes except DomMethods. All the DOM returned will be
63
+ * The returned DOM may includes Nodes, strings, and `domComputed()` values, as well as arrays of
64
+ * any of these. In other words, any `DomArg` goes except `DomMethods`. All the DOM returned will be
55
65
  * disposed when the containing element is disposed, followed by the `owner` itself.
56
66
  */
57
- import { MultiHolder } from './dispose';
58
- import { domComputed } from './domComputed';
59
- import { autoDisposeElem } from './domDispose';
60
67
  export function create(fn, ...args) {
61
- const [markerPre, markerPost, func] = domComputed(null, () => {
62
- // Note that the callback to domComputed() is not called until the markers have been attached
63
- // to the parent element. We attach the MultiHolder's disposal to markerPost the way
64
- // domComputed() normally attaches its own bindings.
65
- const owner = MultiHolder.create(null);
66
- autoDisposeElem(markerPost, owner);
68
+ return domComputedOwned(null, (owner) => {
67
69
  const value = ('create' in fn) ?
68
70
  fn.create(owner, ...args) :
69
71
  fn(owner, ...args);
70
72
  return (value && typeof value === 'object' && 'buildDom' in value) ?
71
73
  value.buildDom() : value;
72
74
  });
73
- return [markerPre, markerPost, func];
74
75
  }
75
76
  //# sourceMappingURL=domComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"domComponent.js","sourceRoot":"","sources":["../../../lib/domComponent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,WAAW,EAAc,MAAM,eAAe,CAAC;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AA0B7C,MAAM,UAAU,MAAM,CAAgC,EAAM,EAAE,GAAG,IAAwB;IACvF,MAAM,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE;QAC3D,6FAA6F;QAC7F,oFAAoF;QACpF,oDAAoD;QACpD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAEnC,MAAM,KAAK,GAAuB,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;YACjD,EAA6B,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;YACtD,EAA4B,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;QAChD,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC"}
1
+ {"version":3,"file":"domComponent.js","sourceRoot":"","sources":["../../../lib/domComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAc,MAAM,eAAe,CAAC;AAuB5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,MAAM,UAAU,MAAM,CAAgC,EAAM,EAAE,GAAG,IAAwB;IACvF,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;QACtC,MAAM,KAAK,GAAuB,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;YACjD,EAA6B,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;YACtD,EAA4B,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;QAChD,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAI,KAAK,CAAC,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { subscribeElem } from './binding';
2
- import { domDispose } from './domDispose';
2
+ import { Holder, MultiHolder } from './dispose';
3
+ import { autoDisposeElem, domDispose } from './domDispose';
3
4
  import { frag } from './domImpl';
4
5
  // Use the browser globals in a way that allows replacing them with mocks in tests.
5
6
  import { G } from './browserGlobals';
@@ -31,6 +32,19 @@ export function domComputed(valueObs, contentFunc = identity) {
31
32
  subscribeElem(markerPost, valueObs, (value) => replaceContent(markerPre, markerPost, contentFunc(value)));
32
33
  }];
33
34
  }
35
+ /**
36
+ * Like domComputed(), but the callback gets an additional first argument, owner, which may be
37
+ * used to take ownership of objects created by the callback. These will be disposed before each
38
+ * new call to the callback, and when the containing DOM is disposed.
39
+ *
40
+ * `domComputedOwned(valueObs, (owner, value) => Editor.create(owner, value).renderSomething())`
41
+ */
42
+ export function domComputedOwned(valueObs, contentFunc) {
43
+ const holder = Holder.create(null);
44
+ const [markerPre, markerPost, func] = domComputed(valueObs, (val) => contentFunc(MultiHolder.create(holder), val));
45
+ autoDisposeElem(markerPost, holder);
46
+ return [markerPre, markerPost, func];
47
+ }
34
48
  function identity(arg) { return arg; }
35
49
  /**
36
50
  * Conditionally appends DOM to an element. The value may be an observable or function (from which
@@ -40,21 +54,34 @@ function identity(arg) { return arg; }
40
54
  * Note that if the observable changes between different truthy values, contentFunc gets called
41
55
  * for each value, and previous content gets destroyed. To consider all truthy values the same,
42
56
  * use an observable that returns a proper boolean, e.g.
43
- *
57
+ * ```ts
44
58
  * dom.maybe(use => Boolean(use(fooObs)), () => dom(...));
59
+ * ```
45
60
  *
46
61
  * As with domComputed(), dom.maybe() may but should not be used when the argument is not an
47
62
  * observable or function. The following are equivalent:
48
- *
63
+ * ```ts
49
64
  * dom(..., dom.maybe(myValue, () => dom(...)));
50
65
  * dom(..., myValue ? dom(...) : null);
66
+ * ```
51
67
  *
52
68
  * The latter is preferred for being simpler.
53
69
  *
54
- * @param boolValueObs: Observable or function for a computed.
55
- * @param contentFunc: Called with the result of boolValueObs when it is truthy. Should return DOM.
70
+ * @param boolValueObs - Observable or function for a computed.
71
+ * @param contentFunc - Called with the result of boolValueObs when it is truthy. Should return DOM.
56
72
  */
57
73
  export function maybe(boolValueObs, contentFunc) {
58
74
  return domComputed(boolValueObs, (value) => value ? contentFunc(value) : null);
59
75
  }
76
+ /**
77
+ * Like maybe(), but the callback gets an additional first argument, owner, which may be used to
78
+ * take ownership of objects created by the callback. These will be disposed before each new call
79
+ * to the callback, and when the condition becomes false or the containing DOM gets disposed.
80
+ * ```ts
81
+ * maybeOwned(showEditor, (owner) => Editor.create(owner).renderSomething())
82
+ * ```
83
+ */
84
+ export function maybeOwned(boolValueObs, contentFunc) {
85
+ return domComputedOwned(boolValueObs, (owner, value) => value ? contentFunc(owner, value) : null);
86
+ }
60
87
  //# sourceMappingURL=domComputed.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"domComputed.js","sourceRoot":"","sources":["../../../lib/domComputed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAC,MAAM,WAAW,CAAC;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAoB,IAAI,EAAC,MAAM,WAAW,CAAC;AAElD,mFAAmF;AACnF,OAAO,EAAC,CAAC,EAAC,MAAM,kBAAkB,CAAC;AAMnC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,UAAgB,EAAE,SAAe,EAAE,OAAe;IAC/E,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC;IACnC,IAAI,IAAI,EAAE;QACR,IAAI,IAAI,CAAC;QACT,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE;YACnE,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC;YACrB,UAAU,CAAC,CAAC,CAAC,CAAC;YACd,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACrB;QACD,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;SACnF;KACF;A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