ripple 0.2.86 → 0.2.87

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.86",
6
+ "version": "0.2.87",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index-client.js",
9
9
  "main": "src/runtime/index-client.js",
@@ -58,6 +58,8 @@
58
58
  "imports": {
59
59
  "#client": "./src/runtime/internal/client/types.d.ts",
60
60
  "#client/constants": "./src/internal/client/constants.js",
61
+ "#server": "./src/runtime/internal/server/types.d.ts",
62
+ "#compiler": "./src/compiler/types/index.d.ts",
61
63
  "#public": "./types/index.d.ts"
62
64
  },
63
65
  "dependencies": {
@@ -1,3 +1,5 @@
1
+ /** @import * as ESTree from 'estree' */
2
+
1
3
  import is_reference from 'is-reference';
2
4
  import { extract_identifiers, object, unwrap_pattern } from '../utils/ast.js';
3
5
  import { walk } from 'zimmerframe';
@@ -0,0 +1,5 @@
1
+
2
+
3
+ export interface CompileResult {
4
+ // TODO
5
+ }
@@ -69,6 +69,7 @@ TrackedArray.fromAsync = async function (arrayLike, mapFn, thisArg) {
69
69
  * @returns {TrackedArray<T>}
70
70
  */
71
71
  function proxy({ elements, block, from_static = false, use_array = false }) {
72
+ /** @type {T[]} */
72
73
  var arr;
73
74
  var first;
74
75
 
@@ -77,9 +78,9 @@ function proxy({ elements, block, from_static = false, use_array = false }) {
77
78
  (first = get_first_if_length(/** @type {Array<T>} */ (elements))) !== undefined
78
79
  ) {
79
80
  arr = new Array();
80
- arr[0] = first;
81
+ arr[0] = /** @type {T} */ (/** @type {unknown} */ (first));
81
82
  } else if (use_array) {
82
- arr = elements;
83
+ arr = /** @type {T[]} */ (elements);
83
84
  } else {
84
85
  arr = new Array(...elements);
85
86
  }
@@ -94,7 +95,7 @@ function proxy({ elements, block, from_static = false, use_array = false }) {
94
95
  var exists = prop in target;
95
96
 
96
97
  if (t === undefined && (!exists || get_descriptor(target, prop)?.writable)) {
97
- t = tracked(exists ? target[prop] : UNINITIALIZED, block);
98
+ t = tracked(exists ? /** @type {any} */ (target)[prop] : UNINITIALIZED, block);
98
99
  tracked_elements.set(prop, t);
99
100
  }
100
101
 
@@ -106,7 +107,7 @@ function proxy({ elements, block, from_static = false, use_array = false }) {
106
107
  var result = Reflect.get(target, prop, receiver);
107
108
 
108
109
  if (typeof result === 'function') {
109
- if (methods_returning_arrays.has(prop)) {
110
+ if (methods_returning_arrays.has(/** @type {string} */ (prop))) {
110
111
  /** @type {(this: any, ...args: any[]) => any} */
111
112
  return function (...args) {
112
113
  var output = Reflect.apply(result, receiver, args);
@@ -211,7 +212,7 @@ function proxy({ elements, block, from_static = false, use_array = false }) {
211
212
 
212
213
  if (t !== undefined || !exists || get_descriptor(target, prop)?.writable) {
213
214
  if (t === undefined) {
214
- t = tracked(exists ? target[prop] : UNINITIALIZED, block);
215
+ t = tracked(exists ? /** @type {any} */ (target)[prop] : UNINITIALIZED, block);
215
216
 
216
217
  tracked_elements.set(prop, t);
217
218
  }
@@ -288,6 +289,12 @@ const methods_returning_arrays = new Set([
288
289
  'with',
289
290
  ]);
290
291
 
292
+ /**
293
+ * @template T
294
+ * @param {Iterable<T>} elements
295
+ * @param {Block} block
296
+ * @returns {TrackedArray<T>}
297
+ */
291
298
  export function tracked_array(elements, block) {
292
299
  return proxy({ elements, block, from_static: true });
293
300
  }
@@ -47,7 +47,6 @@ export {
47
47
  track,
48
48
  trackSplit,
49
49
  untrack,
50
- deferred,
51
50
  } from './internal/client/runtime.js';
52
51
 
53
52
  export { TrackedArray } from './array.js';
@@ -1,5 +1,8 @@
1
- import { DERIVED, TRACKED, UNINITIALIZED } from './internal/client/constants';
2
- import { is_tracked_object } from './internal/client/utils';
1
+ /** @import { Component, Derived, Tracked } from '#server' */
2
+
3
+ import { DERIVED, TRACKED, UNINITIALIZED } from './internal/client/constants.js';
4
+ import { is_tracked_object } from './internal/client/utils.js';
5
+ import { active_component } from './internal/server/index.js';
3
6
 
4
7
  export { create_context as createContext } from './internal/server/context.js';
5
8
 
@@ -9,7 +12,16 @@ export function effect() {
9
12
 
10
13
  export const TrackedArray = Array;
11
14
 
12
- export function track(v, o) {
15
+ var empty_get_set = { get: undefined, set: undefined };
16
+
17
+ /**
18
+ *
19
+ * @param {any} v
20
+ * @param {Function} [get]
21
+ * @param {Function} [set]
22
+ * @returns {Tracked | Derived}
23
+ */
24
+ export function track(v, get, set) {
13
25
  var is_tracked = is_tracked_object(v);
14
26
 
15
27
  if (is_tracked) {
@@ -18,6 +30,8 @@ export function track(v, o) {
18
30
 
19
31
  if (typeof v === 'function') {
20
32
  return {
33
+ a: get || set ? { get, set } : empty_get_set,
34
+ co: active_component,
21
35
  f: TRACKED | DERIVED,
22
36
  fn: v,
23
37
  v: UNINITIALIZED,
@@ -25,6 +39,7 @@ export function track(v, o) {
25
39
  }
26
40
 
27
41
  return {
42
+ a: get || set ? { get, set } : empty_get_set,
28
43
  f: TRACKED,
29
44
  v,
30
45
  };