grainjs 1.0.2 → 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 (138) hide show
  1. package/README.md +23 -71
  2. package/dist/cjs/index.js +5 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/lib/PriorityQueue.d.ts +1 -1
  5. package/dist/cjs/lib/_computed_queue.js +3 -3
  6. package/dist/cjs/lib/_computed_queue.js.map +1 -1
  7. package/dist/cjs/lib/binding.d.ts +11 -4
  8. package/dist/cjs/lib/binding.js +5 -5
  9. package/dist/cjs/lib/binding.js.map +1 -1
  10. package/dist/cjs/lib/computed.d.ts +49 -28
  11. package/dist/cjs/lib/computed.js +38 -52
  12. package/dist/cjs/lib/computed.js.map +1 -1
  13. package/dist/cjs/lib/dispose.d.ts +109 -96
  14. package/dist/cjs/lib/dispose.js +106 -80
  15. package/dist/cjs/lib/dispose.js.map +1 -1
  16. package/dist/cjs/lib/dom.d.ts +38 -18
  17. package/dist/cjs/lib/dom.js +44 -20
  18. package/dist/cjs/lib/dom.js.map +1 -1
  19. package/dist/cjs/lib/domComponent.d.ts +56 -48
  20. package/dist/cjs/lib/domComponent.js +66 -1
  21. package/dist/cjs/lib/domComponent.js.map +1 -1
  22. package/dist/cjs/lib/domComputed.d.ts +31 -21
  23. package/dist/cjs/lib/domComputed.js +14 -11
  24. package/dist/cjs/lib/domComputed.js.map +1 -1
  25. package/dist/cjs/lib/domDispose.d.ts +27 -12
  26. package/dist/cjs/lib/domDispose.js +26 -11
  27. package/dist/cjs/lib/domDispose.js.map +1 -1
  28. package/dist/cjs/lib/domForEach.d.ts +4 -3
  29. package/dist/cjs/lib/domForEach.js +10 -9
  30. package/dist/cjs/lib/domForEach.js.map +1 -1
  31. package/dist/cjs/lib/domImpl.d.ts +33 -10
  32. package/dist/cjs/lib/domImpl.js +28 -9
  33. package/dist/cjs/lib/domImpl.js.map +1 -1
  34. package/dist/cjs/lib/domMethods.d.ts +93 -47
  35. package/dist/cjs/lib/domMethods.js +88 -46
  36. package/dist/cjs/lib/domMethods.js.map +1 -1
  37. package/dist/cjs/lib/domevent.d.ts +87 -62
  38. package/dist/cjs/lib/domevent.js +84 -59
  39. package/dist/cjs/lib/domevent.js.map +1 -1
  40. package/dist/cjs/lib/emit.d.ts +62 -32
  41. package/dist/cjs/lib/emit.js +67 -53
  42. package/dist/cjs/lib/emit.js.map +1 -1
  43. package/dist/cjs/lib/kowrap.d.ts +6 -3
  44. package/dist/cjs/lib/kowrap.js +6 -3
  45. package/dist/cjs/lib/kowrap.js.map +1 -1
  46. package/dist/cjs/lib/obsArray.d.ts +91 -53
  47. package/dist/cjs/lib/obsArray.js +87 -55
  48. package/dist/cjs/lib/obsArray.js.map +1 -1
  49. package/dist/cjs/lib/observable.d.ts +25 -15
  50. package/dist/cjs/lib/observable.js +29 -18
  51. package/dist/cjs/lib/observable.js.map +1 -1
  52. package/dist/cjs/lib/pureComputed.d.ts +12 -15
  53. package/dist/cjs/lib/pureComputed.js +15 -18
  54. package/dist/cjs/lib/pureComputed.js.map +1 -1
  55. package/dist/cjs/lib/styled.d.ts +78 -61
  56. package/dist/cjs/lib/styled.js +26 -79
  57. package/dist/cjs/lib/styled.js.map +1 -1
  58. package/dist/cjs/lib/subscribe.d.ts +41 -37
  59. package/dist/cjs/lib/subscribe.js +31 -40
  60. package/dist/cjs/lib/subscribe.js.map +1 -1
  61. package/dist/cjs/lib/util.js +1 -0
  62. package/dist/cjs/lib/util.js.map +1 -1
  63. package/dist/cjs/lib/widgets/input.d.ts +3 -1
  64. package/dist/cjs/lib/widgets/input.js +6 -4
  65. package/dist/cjs/lib/widgets/input.js.map +1 -1
  66. package/dist/cjs/lib/widgets/select.d.ts +4 -2
  67. package/dist/cjs/lib/widgets/select.js +7 -5
  68. package/dist/cjs/lib/widgets/select.js.map +1 -1
  69. package/dist/esm/lib/_computed_queue.js +3 -3
  70. package/dist/esm/lib/_computed_queue.js.map +1 -1
  71. package/dist/esm/lib/binding.js +2 -2
  72. package/dist/esm/lib/binding.js.map +1 -1
  73. package/dist/esm/lib/computed.js +36 -50
  74. package/dist/esm/lib/computed.js.map +1 -1
  75. package/dist/esm/lib/dispose.js +104 -78
  76. package/dist/esm/lib/dispose.js.map +1 -1
  77. package/dist/esm/lib/dom.js +38 -18
  78. package/dist/esm/lib/dom.js.map +1 -1
  79. package/dist/esm/lib/domComponent.js +65 -0
  80. package/dist/esm/lib/domComponent.js.map +1 -1
  81. package/dist/esm/lib/domComputed.js +10 -7
  82. package/dist/esm/lib/domComputed.js.map +1 -1
  83. package/dist/esm/lib/domDispose.js +26 -11
  84. package/dist/esm/lib/domDispose.js.map +1 -1
  85. package/dist/esm/lib/domForEach.js +3 -2
  86. package/dist/esm/lib/domForEach.js.map +1 -1
  87. package/dist/esm/lib/domImpl.js +26 -7
  88. package/dist/esm/lib/domImpl.js.map +1 -1
  89. package/dist/esm/lib/domMethods.js +77 -35
  90. package/dist/esm/lib/domMethods.js.map +1 -1
  91. package/dist/esm/lib/domevent.js +84 -59
  92. package/dist/esm/lib/domevent.js.map +1 -1
  93. package/dist/esm/lib/emit.js +67 -53
  94. package/dist/esm/lib/emit.js.map +1 -1
  95. package/dist/esm/lib/kowrap.js +5 -2
  96. package/dist/esm/lib/kowrap.js.map +1 -1
  97. package/dist/esm/lib/obsArray.js +82 -50
  98. package/dist/esm/lib/obsArray.js.map +1 -1
  99. package/dist/esm/lib/observable.js +26 -15
  100. package/dist/esm/lib/observable.js.map +1 -1
  101. package/dist/esm/lib/pureComputed.js +15 -18
  102. package/dist/esm/lib/pureComputed.js.map +1 -1
  103. package/dist/esm/lib/styled.js +24 -77
  104. package/dist/esm/lib/styled.js.map +1 -1
  105. package/dist/esm/lib/subscribe.js +27 -36
  106. package/dist/esm/lib/subscribe.js.map +1 -1
  107. package/dist/esm/lib/util.js +1 -0
  108. package/dist/esm/lib/util.js.map +1 -1
  109. package/dist/esm/lib/widgets/input.js +3 -1
  110. package/dist/esm/lib/widgets/input.js.map +1 -1
  111. package/dist/esm/lib/widgets/select.js +3 -1
  112. package/dist/esm/lib/widgets/select.js.map +1 -1
  113. package/dist/grain-full.debug.js +2146 -3062
  114. package/dist/grain-full.debug.js.map +7 -0
  115. package/dist/grain-full.min.js +6 -2
  116. package/dist/grain-full.min.js.map +7 -1
  117. package/lib/binding.ts +9 -2
  118. package/lib/computed.ts +56 -56
  119. package/lib/dispose.ts +110 -85
  120. package/lib/dom.ts +39 -20
  121. package/lib/domComponent.ts +66 -57
  122. package/lib/domComputed.ts +29 -19
  123. package/lib/domDispose.ts +28 -11
  124. package/lib/domForEach.ts +7 -3
  125. package/lib/domImpl.ts +30 -7
  126. package/lib/domMethods.ts +101 -46
  127. package/lib/domevent.ts +85 -60
  128. package/lib/emit.ts +64 -50
  129. package/lib/kowrap.ts +5 -2
  130. package/lib/obsArray.ts +89 -54
  131. package/lib/observable.ts +26 -15
  132. package/lib/pureComputed.ts +16 -22
  133. package/lib/styled.ts +85 -71
  134. package/lib/subscribe.ts +41 -45
  135. package/lib/util.ts +1 -0
  136. package/lib/widgets/input.ts +3 -1
  137. package/lib/widgets/select.ts +3 -1
  138. package/package.json +38 -27
package/README.md CHANGED
@@ -1,86 +1,38 @@
1
- # GrainJS
1
+ # GrainJS: a light typescript web framework
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/grainjs.svg)](https://badge.fury.io/js/grainjs)
4
- [![Build Status](https://travis-ci.org/gristlabs/grainjs.svg?branch=master)](https://travis-ci.org/gristlabs/grainjs)
4
+ [![Build status](https://github.com/gristlabs/grainjs/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/gristlabs/grainjs/actions/workflows/build-and-test.yml)
5
+ [![codecov](https://codecov.io/gh/gristlabs/grainjs/branch/main/graph/badge.svg?token=1OIMMBLI6N)](https://codecov.io/gh/gristlabs/grainjs)
5
6
 
6
- GrainJS is a Javascript (and TypeScript) library for building highly performant dynamic
7
- applications.
7
+ GrainJS is a JavaScript / TypeScript library for building dynamic web applications.
8
8
 
9
- GrainJS provides convenient pure-JS interfaces for building DOM. It has observables inspired by
10
- [Knockout](http://knockoutjs.com/documentation/introduction.html) to create declarative data
11
- models and tie them to UI. It includes light-weight event dispatching, DOM event subscriptions,
12
- disposable components, and in-code CSS styling.
9
+ - It's in part inspired by [React](https://reactjs.org/), but based on observables (like
10
+ [Knockout](http://knockoutjs.com/documentation/introduction.html)) instead of virtual dom.
11
+ - It is lightweight, has no dependencies, and takes only ~30KB minified.
12
+ - It needs no special tooling. It's nothing more than a library.
13
+ - It supports convenient DOM-building in JS, event dispatching, DOM event subscriptions,
14
+ disposable components, and in-code CSS styling.
15
+ - It's fully typed for use with TypeScript.
16
+ - It's proven its worth by powering [Grist](https://github.com/gristlabs/grist-core#grist)'s rich
17
+ frontend app.
13
18
 
14
- GrainJS is in part inspired by [React](https://reactjs.org/), but based on observables instead of
15
- virtual dom, and with a convenient way to build DOM without JSX. It is lighter weight, and has
16
- less magic happening under the covers.
19
+ ## Documentation
17
20
 
18
- The focus is on performance and conciseness. The library has no dependencies and is only 31K.
19
- minified.
21
+ For docs, visit [https://gristlabs.github.io/grainjs/](https://gristlabs.github.io/grainjs/).
20
22
 
21
23
  ## Installation
22
24
 
25
+ ```sh
26
+ npm install grainjs
23
27
  ```
24
- npm install --save grainjs
25
- ```
26
-
27
- ## Basic Example
28
-
29
- ```typescript
30
- const name = observable("");
31
-
32
- dom.update(document.body,
33
- dom('input', {type: 'text', placeholder: 'Enter your name'},
34
- dom.on('input', (ev, elem) => name.set(elem.value)),
35
- ),
36
- dom('div', 'Hello, ',
37
- dom.text((use) => use(name).toUpperCase() || 'Stranger'),
38
- '!',
39
- ),
40
- );
41
- ```
42
-
43
- # Documentation
44
-
45
- At a basic level, GrainJS allows you to describe DOM structure in one place, using Javascript (or
46
- TypeScript), and to keep the dynamic aspects of it separated into variables called "observables".
47
- These observables serve as the model of the UI; other code can update them to cause UI to update,
48
- without knowing the details of the DOM construction.
49
-
50
- In addition, the library provides approaches to create and dispose resources (important for
51
- long-lived single-page applications), and an assortment of other related tools.
52
28
 
53
- - [DOM & Observables](docs/basics.md)
54
- - [DOM Construction](docs/basics.md#dom-construction)
55
- - [Observables](docs/basics.md#observables)
56
- - [Computed Observables](docs/basics.md#computed-observables)
57
- - [DOM Bindings](docs/basics.md#dom-bindings)
58
- - [Conditional DOM](docs/basics.md#conditional-dom)
59
- - [Repeating DOM](docs/basics.md#repeating-dom)
60
- - [DOM Events](docs/basics.md#dom-events)
61
- - [Styling DOM](docs/basics.md#styling-dom)
29
+ Or see [Getting started with GrainJS](https://gristlabs.github.io/grainjs/getting-started.html).
62
30
 
63
- - [Disposables](docs/dispose.md)
64
- - [Class Disposable](docs/dispose.md#class-disposable)
65
- - [Taking Ownership](docs/dispose.md#taking-ownership)
66
- - [Holders](docs/dispose.md#holders)
67
- - [Further Notes](docs/dispose.md#further-notes)
31
+ ## Examples
68
32
 
69
- - [More on Observables](docs/more-observables.md)
70
- - [Subscribe](docs/more-observables.md#subscribe)
71
- - [Disposable Values](docs/more-observables.md#disposable-values)
72
- - [ObsArray](docs/more-observables.md#obsarray)
73
- - [PureComputed](docs/more-observables.md#purecomputed)
74
- - [Order of Evaluation](docs/more-observables.md#order-of-evaluation)
33
+ See basic examples in [Quick tour](https://gristlabs.github.io/grainjs/#quick-tour) or complete examples
34
+ at [Examples](https://gristlabs.github.io/grainjs/examples.html).
75
35
 
76
- - [Miscellaneous](docs/misc.md)
77
- - [Event Emitters](docs/misc.md#event-emitters)
78
- - [Disposing DOM](docs/misc.md#disposing-dom)
79
- - [DOM Components](docs/misc.md#dom-components)
80
- - [Functional Components](docs/misc.md#functional-components)
81
- - [Knockout Integration](docs/misc.md#knockout-integration)
36
+ ## License
82
37
 
83
- - [Reference](docs/reference.md)
84
- - [DOM Reference](docs/reference.md#dom-reference)
85
- - [Disposables Reference](docs/reference.md#disposables-reference)
86
- - [Observables Reference](docs/reference.md#observables-reference)
38
+ GrainJS is licensed under [Apache-2.0 license](https://github.com/gristlabs/grainjs/blob/main/LICENSE).
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,+CAA6B;AAC7B,kDAAgC;AAChC,6CAA2B;AAC3B,sDAAoC;AACpC,uDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,+CAA6B;AAC7B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,+CAA6B;AAC7B,kDAAgC;AAChC,6CAA2B;AAC3B,sDAAoC;AACpC,uDAAqC"}
@@ -6,7 +6,7 @@
6
6
  * It is constructed with a function that returns which of two items is "prior"; the pop() method
7
7
  * returns the most-prior element.
8
8
  */
9
- export declare type IsPriorFunc<T> = (a: T, b: T) => boolean;
9
+ export type IsPriorFunc<T> = (a: T, b: T) => boolean;
10
10
  export declare class PriorityQueue<T> {
11
11
  private _isPrior;
12
12
  private _items;
@@ -24,6 +24,9 @@ const PriorityQueue_1 = require("./PriorityQueue");
24
24
  * for subscriptions and computed observables.
25
25
  */
26
26
  class DepItem {
27
+ static isPrioritySmaller(a, b) {
28
+ return a._priority < b._priority || (a._priority === b._priority && a._creation < b._creation);
29
+ }
27
30
  /**
28
31
  * Callback should call depItem.useDep(dep) for each DepInput it depends on.
29
32
  */
@@ -35,9 +38,6 @@ class DepItem {
35
38
  this._callback = callback;
36
39
  this._context = optContext;
37
40
  }
38
- static isPrioritySmaller(a, b) {
39
- return a._priority < b._priority || (a._priority === b._priority && a._creation < b._creation);
40
- }
41
41
  /**
42
42
  * Mark depItem as a dependency of this DepItem. The argument may be null to indicate a leaf (an
43
43
  * item such as a plain observable, which does not itself depend on anything else).
@@ -1 +1 @@
1
- {"version":3,"file":"_computed_queue.js","sourceRoot":"","sources":["../../../lib/_computed_queue.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,mDAA8C;AAE9C;;;GAGG;AACH,MAAa,OAAO;IAalB;;OAEG;IACH,YAAY,QAAoB,EAAE,UAAmB;QAX7C,cAAS,GAAW,CAAC,CAAC;QACtB,cAAS,GAAY,KAAK,CAAC;QAInC,+DAA+D;QACvD,cAAS,GAAW,EAAE,gBAAgB,CAAC;QAM7C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC;IAC7B,CAAC;IAlBM,MAAM,CAAC,iBAAiB,CAAC,CAAU,EAAE,CAAU;QACpD,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IACjG,CAAC;IAkBD;;;OAGG;IACI,MAAM,CAAC,OAAqB;QACjC,MAAM,CAAC,GAAG,OA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E;YAC3E,GAAG;gBACD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACjB,IAAI,CAAC,SAAS,EAAE,CAAC;aAClB,QAAQ,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE;SAC1B;gBAAS;YACR,2FAA2F;YAC3F,0DAA0D;YAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;gBACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;aACxB;YACD,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACjB,WAAW,EAAE,CAAC;SACf;KACF;AACH,CAAC;AArBD,0BAqBC;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAI,IAAa;IAC5C,IAAI;QACF,WAAW,EAAE,CAAC;QACd,OAAO,IAAI,EAAE,CAAC;KACf;YAAS;QACR,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AARD,sCAQC"}
@@ -6,8 +6,15 @@ import { IDisposable } from './dispose';
6
6
  import { IKnockoutReadObservable, InferKoType } from './kowrap';
7
7
  import { BaseObservable } from './observable';
8
8
  import { UseCBOwner } from './subscribe';
9
- export declare type BindableValue<T> = BaseObservable<T> | ComputedCallback<T> | T | IKnockoutReadObservable<T>;
10
- export declare type ComputedCallback<T> = (use: UseCBOwner, ...args: any[]) => T;
9
+ /**
10
+ * Any of the value types that DOM methods know how to subscribe to: a plain value (like a
11
+ * string); an Observable (including a Computed); a knockout observable; a function.
12
+ *
13
+ * If a function, it's used to create a `Computed`, and will be called with a context function
14
+ * `use`, allowing it to depend on other observable values (see documentation for `Computed`).
15
+ */
16
+ export type BindableValue<T> = BaseObservable<T> | ComputedCallback<T> | T | IKnockoutReadObservable<T>;
17
+ export type ComputedCallback<T> = (use: UseCBOwner, ...args: any[]) => T;
11
18
  /**
12
19
  * Subscribes a callback to valueObs, which may be one a plain value, an observable, a knockout
13
20
  * observable, or a function. If a function, it's used to create a computed() and will be called
@@ -22,7 +29,7 @@ export declare type ComputedCallback<T> = (use: UseCBOwner, ...args: any[]) => T
22
29
  export declare function subscribeBindable<KObs extends IKnockoutReadObservable<any>>(valueObs: KObs, callback: (val: InferKoType<KObs>) => void): IDisposable | null;
23
30
  export declare function subscribeBindable<T>(valueObs: BindableValue<T>, callback: (val: T) => void): IDisposable | null;
24
31
  /**
25
- * Subscribes a callback to valueObs (which may be a value, observable, or function) using
26
- * subscribe(), and disposes the subscription with the passed-in element.
32
+ * Subscribes a callback to `valueObs` (which may be a value, observable, or function) using
33
+ * `subscribeBindable()`, and ties the disposal of this subscription to the passed-in element.
27
34
  */
28
35
  export declare function subscribeElem<T>(elem: Node, valueObs: BindableValue<T>, callback: (newVal: T, oldVal?: T) => void): void;
@@ -23,7 +23,7 @@ function subscribeBindable(valueObs, callback) {
23
23
  // let sub = subscribe(use => callback(valueObs(use)));
24
24
  // The difference is that when valueObs() evaluates to unchanged value, callback would be
25
25
  // called in the version above, but not in the version below.
26
- const comp = computed_1.computed(valueObs);
26
+ const comp = (0, computed_1.computed)(valueObs);
27
27
  comp.addListener((val) => callback(val));
28
28
  callback(comp.get());
29
29
  return comp; // Disposing this will dispose its one listener.
@@ -32,18 +32,18 @@ function subscribeBindable(valueObs, callback) {
32
32
  if (valueObs instanceof observable_1.BaseObservable) {
33
33
  // Use subscribe() rather than addListener(), so that bundling of changes (implicit and with
34
34
  // bundleChanges()) is respected. This matters when callback also uses observables.
35
- return subscribe_1.subscribe(valueObs, (use, val) => callback(val));
35
+ return (0, subscribe_1.subscribe)(valueObs, (use, val) => callback(val));
36
36
  }
37
37
  callback(valueObs);
38
38
  return null;
39
39
  }
40
40
  exports.subscribeBindable = subscribeBindable;
41
41
  /**
42
- * Subscribes a callback to valueObs (which may be a value, observable, or function) using
43
- * subscribe(), and disposes the subscription with the passed-in element.
42
+ * Subscribes a callback to `valueObs` (which may be a value, observable, or function) using
43
+ * `subscribeBindable()`, and ties the disposal of this subscription to the passed-in element.
44
44
  */
45
45
  function subscribeElem(elem, valueObs, callback) {
46
- domDispose_1.autoDisposeElem(elem, subscribeBindable(valueObs, callback));
46
+ (0, domDispose_1.autoDisposeElem)(elem, subscribeBindable(valueObs, callback));
47
47
  }
48
48
  exports.subscribeElem = subscribeElem;
49
49
  //# sourceMappingURL=binding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../../lib/binding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yCAAoC;AAEpC,6CAA6C;AAE7C,6CAA4C;AAC5C,2CAAkD;AAsBlD,SAAgB,iBAAiB,CAC7B,QAA0B,EAAE,QAA0B;IACxD,wEAAwE;IACxE,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,uBAAuB;QACvB,MAAM,OAAO,GAAG,QAAsC,CAAC;QACvD,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;YACtC,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YACtD,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YACzB,OAAO,GAAG,CAAC;SACZ;QAED,6EAA6E;QAC7E,0DAA0D;QAC1D,yFAAyF;QACzF,6DAA6D;QAC7D,MAAM,IAAI,GAAG,mBAAQ,CAAC,QAA+B,CAAC,CAAC;QACvD,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC,CAAM,gDAAgD;KACnE;IAED,iBAAiB;IACjB,IAAI,QAAQ,YAAY,2BAAc,EAAE;QACtC,4FAA4F;QAC5F,mFAAmF;QACnF,OAAO,qBAAS,CAAC,Q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AAM,gDAAgD;KACnE;IAED,iBAAiB;IACjB,IAAI,QAAQ,YAAY,2BAAc,EAAE;QACtC,4FAA4F;QAC5F,mFAAmF;QACnF,OAAO,IAAA,qBAAS,EAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;KACzD;IAED,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnB,OAAO,IAAI,CAAC;AACd,CAAC;AA/BD,8CA+BC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAI,IAAU,EAAE,QAA0B,EACtC,QAAyC;IACxE,IAAA,4BAAe,EAAC,IAAI,EAAE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC;AAHD,sCAGC"}
@@ -1,44 +1,62 @@
1
+ import { DepItem } from './_computed_queue';
2
+ import { IDisposableOwnerT } from './dispose';
3
+ import { BaseObservable as Obs, Observable } from './observable';
4
+ import { ISubscribable, UseCBOwner as UseCB } from './subscribe';
5
+ /** @internal */
6
+ type Owner<T> = IDisposableOwnerT<Computed<T>> | null;
1
7
  /**
2
- * computed.js implements a computed observable, whose value depends on other observables and gets
8
+ * `Computed` implements a computed observable, whose value depends on other observables and gets
3
9
  * recalculated automatically when they change.
4
10
  *
5
- * E.g. if we have some existing observables (which may themselves be instances of `computed`),
11
+ * E.g. if we have some existing observables (which may themselves be instances of `Computed`),
6
12
  * we can create a computed that subscribes to them explicitly:
7
- * let obs1 = observable(5), obs2 = observable(12);
8
- * let computed1 = computed(obs1, obs2, (use, v1, v2) => v1 + v2);
13
+ * ```ts
14
+ * const obs1 = Observable.create(null, 5), obs2 = Observable.create(null, 12);
15
+ * const computed1 = Computed.create(null, obs1, obs2, (use, v1, v2) => v1 + v2);
16
+ * ```
9
17
  *
10
18
  * or implicitly by using `use(obs)` function:
11
- * let computed2 = computed(use => use(obs1) + use(obs2));
19
+ * ```ts
20
+ * const computed2 = Computed.create(null, use => use(obs1) + use(obs2));
21
+ * ```
12
22
  *
13
- * In either case, computed1.get() and computed2.get() will have the value 17. If obs1 or obs2 is
14
- * changed, computed1 and computed2 will get recomputed automatically.
23
+ * In either case, `computed1.get()` and `computed2.get()` will have the value 17. If `obs1` or
24
+ * `obs2` is changed, `computed1` and `computed2` will get recomputed automatically.
15
25
  *
16
26
  * Creating a computed allows any number of dependencies to be specified explicitly, and their
17
- * values will be passed to the read() callback. These may be combined with automatic dependencies
18
- * detected using use(). Note that constructor dependencies have less overhead.
19
- *
20
- * let val = computed(...deps, ((use, ...depValues) => READ_CALLBACK));
27
+ * values will be passed to the `read()` callback. These may be combined with automatic dependencies
28
+ * detected using `use()`. Note that constructor dependencies have less overhead.
29
+ * ```ts
30
+ * const val = Computed.create(null, ...deps, ((use, ...depValues) => READ_CALLBACK));
31
+ * ```
21
32
  *
22
33
  * You may specify a `write` callback by calling `onWrite(WRITE_CALLBACK)`, which will be called
23
- * whenever set() is called on the computed by its user. If a `write` bacllback is not specified,
34
+ * whenever `set()` is called on the computed by its user. If a `write` bacllback is not specified,
24
35
  * calling `set` on a computed observable will throw an exception.
25
36
  *
26
- * Note that pureComputed.js offers a variation of computed() with the same interface, but which
37
+ * Note that `PureComputed` offers a variation of `Computed` with the same interface, but which
27
38
  * stays unsubscribed from dependencies while it itself has no subscribers.
28
39
  *
29
40
  * A computed may be used with a disposable value using `use.owner` as the value's owner. E.g.
30
- * let val = computed((use) => Foo.create(use.owner, use(a), use(b)));
41
+ * ```ts
42
+ * const val = Computed.create(null, ((use) => Foo.create(use.owner, use(a), use(b)));
43
+ * ```
31
44
  *
32
- * When the computed() is re-evaluated, and when it itself is disposed, it disposes the previously
33
- * owned value. Note that only the pattern above works, i.e. use.owner may only be used to take
45
+ * When the `Computed` is re-evaluated, and when it itself is disposed, it disposes the previously
46
+ * owned value. Note that only the pattern above works, i.e. `use.owner` may only be used to take
34
47
  * ownership of the same disposable that the callback returns.
35
48
  */
36
- import { DepItem } from './_computed_queue';
37
- import { IDisposableOwnerT } from './dispose';
38
- import { BaseObservable as Obs, Observable } from './observable';
39
- import { ISubscribable, UseCBOwner as UseCB } from './subscribe';
40
- declare type Owner<T> = IDisposableOwnerT<Computed<T>> | null;
41
49
  export declare class Computed<T> extends Observable<T> {
50
+ /**
51
+ * Creates a new Computed, owned by the given owner.
52
+ * @param owner - Object to own this Computed, or null to handle disposal manually.
53
+ * @param observables - Zero or more observables on which this computes depends. The callback
54
+ * will get called when any of these changes.
55
+ * @param callback - Read callback that will be called with `(use, ...values)`,
56
+ * i.e. the `use` function and values for all of the `...observables`. The callback is called
57
+ * immediately and whenever any dependency changes.
58
+ * @returns The newly created `Computed` observable.
59
+ */
42
60
  static create<T>(owner: Owner<T>, cb: (use: UseCB) => T): Computed<T>;
43
61
  static create<T, A>(owner: Owner<T>, a: Obs<A>, cb: (use: UseCB, a: A) => T): Computed<T>;
44
62
  static create<T, A, B>(owner: Owner<T>, a: Obs<A>, b: Obs<B>, cb: (use: UseCB, a: A, b: B) => T): Computed<T>;
@@ -48,18 +66,16 @@ export declare class Computed<T> extends Observable<T> {
48
66
  private _callback;
49
67
  private _write;
50
68
  private _sub;
51
- /**
52
- * Internal constructor for a Computed observable. You should use computed() function instead.
53
- */
54
69
  constructor(callback: (use: UseCB, ...args: any[]) => T, dependencies: ISubscribable[]);
55
70
  /**
56
71
  * Used by subscriptions to keep track of dependencies.
72
+ * @internal
57
73
  */
58
74
  _getDepItem(): DepItem;
59
75
  /**
60
76
  * "Sets" the value of the computed by calling the write() callback if one was provided in the
61
77
  * constructor. Throws an error if there was no such callback (not a "writable" computed).
62
- * @param {Object} value: The value to pass to the write() callback.
78
+ * @param value - The value to pass to the write() callback.
63
79
  */
64
80
  set(value: T): void;
65
81
  /**
@@ -74,9 +90,14 @@ export declare class Computed<T> extends Observable<T> {
74
90
  private _read;
75
91
  }
76
92
  /**
77
- * This is the type-checking interface for computed(), which allows TypeScript to do helpful
78
- * type-checking when using it. We can only support a fixed number of argumnets (explicit
79
- * dependencies), but 5 should almost always be enough.
93
+ * Creates a new Computed.
94
+ * @param observables - The initial params, of which there may be zero or more, are
95
+ * observables on which this computed depends. When any of them change, the `read()` callback
96
+ * will be called with the values of these observables as arguments.
97
+ * @param readCallback - Read callback that will be called with `(use, ...values)`,
98
+ * i.e. the `use` function and values for all of the `...observables`. The callback is called
99
+ * immediately and whenever any dependency changes.
100
+ * @returns The newly created `Computed` observable.
80
101
  */
81
102
  export declare function computed<T>(cb: (use: UseCB) => T): Computed<T>;
82
103
  export declare function computed<T, A>(a: Obs<A>, cb: (use: UseCB, a: A) => T): Computed<T>;
@@ -1,51 +1,60 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computed = exports.Computed = void 0;
4
+ const dispose_1 = require("./dispose");
5
+ const observable_1 = require("./observable");
6
+ const subscribe_1 = require("./subscribe");
7
+ function _noWrite() {
8
+ throw new Error("Can't write to non-writable computed");
9
+ }
2
10
  /**
3
- * computed.js implements a computed observable, whose value depends on other observables and gets
11
+ * `Computed` implements a computed observable, whose value depends on other observables and gets
4
12
  * recalculated automatically when they change.
5
13
  *
6
- * E.g. if we have some existing observables (which may themselves be instances of `computed`),
14
+ * E.g. if we have some existing observables (which may themselves be instances of `Computed`),
7
15
  * we can create a computed that subscribes to them explicitly:
8
- * let obs1 = observable(5), obs2 = observable(12);
9
- * let computed1 = computed(obs1, obs2, (use, v1, v2) => v1 + v2);
16
+ * ```ts
17
+ * const obs1 = Observable.create(null, 5), obs2 = Observable.create(null, 12);
18
+ * const computed1 = Computed.create(null, obs1, obs2, (use, v1, v2) => v1 + v2);
19
+ * ```
10
20
  *
11
21
  * or implicitly by using `use(obs)` function:
12
- * let computed2 = computed(use => use(obs1) + use(obs2));
22
+ * ```ts
23
+ * const computed2 = Computed.create(null, use => use(obs1) + use(obs2));
24
+ * ```
13
25
  *
14
- * In either case, computed1.get() and computed2.get() will have the value 17. If obs1 or obs2 is
15
- * changed, computed1 and computed2 will get recomputed automatically.
26
+ * In either case, `computed1.get()` and `computed2.get()` will have the value 17. If `obs1` or
27
+ * `obs2` is changed, `computed1` and `computed2` will get recomputed automatically.
16
28
  *
17
29
  * Creating a computed allows any number of dependencies to be specified explicitly, and their
18
- * values will be passed to the read() callback. These may be combined with automatic dependencies
19
- * detected using use(). Note that constructor dependencies have less overhead.
20
- *
21
- * let val = computed(...deps, ((use, ...depValues) => READ_CALLBACK));
30
+ * values will be passed to the `read()` callback. These may be combined with automatic dependencies
31
+ * detected using `use()`. Note that constructor dependencies have less overhead.
32
+ * ```ts
33
+ * const val = Computed.create(null, ...deps, ((use, ...depValues) => READ_CALLBACK));
34
+ * ```
22
35
  *
23
36
  * You may specify a `write` callback by calling `onWrite(WRITE_CALLBACK)`, which will be called
24
- * whenever set() is called on the computed by its user. If a `write` bacllback is not specified,
37
+ * whenever `set()` is called on the computed by its user. If a `write` bacllback is not specified,
25
38
  * calling `set` on a computed observable will throw an exception.
26
39
  *
27
- * Note that pureComputed.js offers a variation of computed() with the same interface, but which
40
+ * Note that `PureComputed` offers a variation of `Computed` with the same interface, but which
28
41
  * stays unsubscribed from dependencies while it itself has no subscribers.
29
42
  *
30
43
  * A computed may be used with a disposable value using `use.owner` as the value's owner. E.g.
31
- * let val = computed((use) => Foo.create(use.owner, use(a), use(b)));
44
+ * ```ts
45
+ * const val = Computed.create(null, ((use) => Foo.create(use.owner, use(a), use(b)));
46
+ * ```
32
47
  *
33
- * When the computed() is re-evaluated, and when it itself is disposed, it disposes the previously
34
- * owned value. Note that only the pattern above works, i.e. use.owner may only be used to take
48
+ * When the `Computed` is re-evaluated, and when it itself is disposed, it disposes the previously
49
+ * owned value. Note that only the pattern above works, i.e. `use.owner` may only be used to take
35
50
  * ownership of the same disposable that the callback returns.
36
51
  */
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.computed = exports.Computed = void 0;
39
- const dispose_1 = require("./dispose");
40
- const observable_1 = require("./observable");
41
- const subscribe_1 = require("./subscribe");
42
- function _noWrite() {
43
- throw new Error("Can't write to non-writable computed");
44
- }
45
52
  class Computed extends observable_1.Observable {
46
- /**
47
- * Internal constructor for a Computed observable. You should use computed() function instead.
48
- */
53
+ static create(owner, ...args) {
54
+ const readCb = args.pop();
55
+ return (0, dispose_1.setDisposeOwner)(owner, new Computed(readCb, args));
56
+ }
57
+ // Internal constructor for a Computed observable. You should use computed() function instead.
49
58
  constructor(callback, dependencies) {
50
59
  // At initialization we force an undefined value even though it's not of type T: it gets set
51
60
  // to a proper value during the creation of new Subscription, which calls this._read.
@@ -54,22 +63,9 @@ class Computed extends observable_1.Observable {
54
63
  this._write = _noWrite;
55
64
  this._sub = new subscribe_1.Subscription(this._read.bind(this), dependencies, this);
56
65
  }
57
- /**
58
- * Creates a new Computed, owned by the given owner.
59
- * @param owner: Object to own this Computed, or null to handle disposal manually.
60
- * @param ...observables: Zero or more observables on which this computes depends. The callback
61
- * will get called when any of these changes.
62
- * @param callback: Read callback that will be called with (use, ...values),
63
- * i.e. the `use` function and values for all of the ...observables. The callback is called
64
- * immediately and whenever any dependency changes.
65
- * @returns {Computed} The newly created computed observable.
66
- */
67
- static create(owner, ...args) {
68
- const readCb = args.pop();
69
- return dispose_1.setDisposeOwner(owner, new Computed(readCb, args));
70
- }
71
66
  /**
72
67
  * Used by subscriptions to keep track of dependencies.
68
+ * @internal
73
69
  */
74
70
  _getDepItem() {
75
71
  return this._sub._getDepItem();
@@ -77,7 +73,7 @@ class Computed extends observable_1.Observable {
77
73
  /**
78
74
  * "Sets" the value of the computed by calling the write() callback if one was provided in the
79
75
  * constructor. Throws an error if there was no such callback (not a "writable" computed).
80
- * @param {Object} value: The value to pass to the write() callback.
76
+ * @param value - The value to pass to the write() callback.
81
77
  */
82
78
  set(value) { this._write(value); }
83
79
  /**
@@ -100,16 +96,6 @@ class Computed extends observable_1.Observable {
100
96
  }
101
97
  }
102
98
  exports.Computed = Computed;
103
- /**
104
- * Creates a new Computed.
105
- * @param {Observable} ...observables: The initial params, of which there may be zero or more, are
106
- * observables on which this computed depends. When any of them change, the read() callback
107
- * will be called with the values of these observables as arguments.
108
- * @param {Function} readCallback: Read callback that will be called with (use, ...values),
109
- * i.e. the `use` function and values for all of the ...observables. The callback is called
110
- * immediately and whenever any dependency changes.
111
- * @returns {Computed} The newly created computed observable.
112
- */
113
99
  function computed(...args) {
114
100
  const readCb = args.pop();
115
101
  return new Computed(readCb, args);
@@ -1 +1 @@
1
- {"version":3,"file":"computed.js","sourceRoot":"","sources":["../../../lib/computed.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAGH,uCAA6D;AAC7D,6CAA+D;AAC/D,2CAA6E;AAE7E,SAAS,QAAQ;IACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;AAC1D,CAAC;AAID,MAAa,QAAY,SAAQ,uBAAa;IAuC5C;;OAEG;IACH,YAAY,QAA2C,EAAE,YAA6B;QACpF,4FAA4F;QAC5F,qFAAqF;QACrF,KAAK,CAAC,SAAgB,CAAC,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IAC1E,CAAC;IA7BD;;;;;;;;;OASG;IACI,MAAM,CAAC,MAAM,CAAI,KAA0C,EAAE,GAAG,IAAW;QAChF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1B,OAAO,yBAAe,CAAC,KAAK,EAAE,IAAI,QAAQ,CAAI,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAkBD;;OAEG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;I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