ripple 0.2.205 → 0.2.206

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is an elegant TypeScript UI framework",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.205",
6
+ "version": "0.2.206",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index-client.js",
9
9
  "main": "src/runtime/index-client.js",
@@ -97,6 +97,6 @@
97
97
  "vscode-languageserver-types": "^3.17.5"
98
98
  },
99
99
  "peerDependencies": {
100
- "ripple": "0.2.205"
100
+ "ripple": "0.2.206"
101
101
  }
102
102
  }
@@ -7,10 +7,10 @@ import { active_component } from './runtime.js';
7
7
  */
8
8
  export class Context {
9
9
  /**
10
- * @param {T} initial_value
10
+ * @param {T} [initial_value]
11
11
  */
12
12
  constructor(initial_value) {
13
- /** @type {T} */
13
+ /** @type {T | undefined} */
14
14
  this._v = initial_value;
15
15
  }
16
16
 
@@ -6,55 +6,55 @@ import { active_component } from './index.js';
6
6
  * @template T
7
7
  */
8
8
  export class Context {
9
- /**
10
- * @param {T} initial_value
11
- */
12
- constructor(initial_value) {
13
- /** @type {T} */
14
- this._v = initial_value;
15
- }
16
-
17
- get() {
18
- const component = active_component;
19
- const context = this;
20
-
21
- if (component === null) {
22
- throw new Error('No active component found, cannot get context');
23
- }
24
- /** @type {Component | null} */
25
- let current_component = component;
26
-
27
- while (current_component !== null) {
28
- const context_map = current_component.c;
29
-
30
- if (context_map?.has(context)) {
31
- return context_map.get(context);
32
- }
33
-
34
- current_component = current_component.p;
35
- }
36
-
37
- return context._v;
38
- }
39
-
40
- /**
41
- * @template T
42
- * @param {T} value
43
- */
44
- set(value) {
45
- const component = active_component;
46
- const context = this;
47
-
48
- if (component === null) {
49
- throw new Error('No active component found, cannot set context');
50
- }
51
-
52
- let current_context = component.c;
53
-
54
- if (current_context === null) {
55
- current_context = component.c = new Map();
56
- }
57
-
58
- current_context.set(context, value);
59
- }
9
+ /**
10
+ * @param {T} [initial_value]
11
+ */
12
+ constructor(initial_value) {
13
+ /** @type {T | undefined} */
14
+ this._v = initial_value;
15
+ }
16
+
17
+ get() {
18
+ const component = active_component;
19
+ const context = this;
20
+
21
+ if (component === null) {
22
+ throw new Error('No active component found, cannot get context');
23
+ }
24
+ /** @type {Component | null} */
25
+ let current_component = component;
26
+
27
+ while (current_component !== null) {
28
+ const context_map = current_component.c;
29
+
30
+ if (context_map?.has(context)) {
31
+ return context_map.get(context);
32
+ }
33
+
34
+ current_component = current_component.p;
35
+ }
36
+
37
+ return context._v;
38
+ }
39
+
40
+ /**
41
+ * @template T
42
+ * @param {T} value
43
+ */
44
+ set(value) {
45
+ const component = active_component;
46
+ const context = this;
47
+
48
+ if (component === null) {
49
+ throw new Error('No active component found, cannot set context');
50
+ }
51
+
52
+ let current_context = component.c;
53
+
54
+ if (current_context === null) {
55
+ current_context = component.c = new Map();
56
+ }
57
+
58
+ current_context.set(context, value);
59
+ }
60
60
  }
package/types/index.d.ts CHANGED
@@ -39,8 +39,8 @@ export interface TrackedArray<T> extends Array<T> {}
39
39
 
40
40
  export const TrackedArray: TrackedArrayConstructor;
41
41
 
42
- export class Context<T> {
43
- constructor(initial_value: T);
42
+ export class Context<T = undefined> {
43
+ constructor(initial_value?: T);
44
44
  get(): T;
45
45
  set(value: T): void;
46
46
  #private;