creo 0.0.3-dev → 0.0.4-dev

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 (48) hide show
  1. package/.env.development +1 -0
  2. package/.github/workflows/main.yml +24 -0
  3. package/README.md +1 -1
  4. package/TODOS.md +2 -0
  5. package/index.ts +1 -0
  6. package/package.json +7 -2
  7. package/src/DOM/Context.ts +36 -0
  8. package/src/DOM/DomEngine.ts +106 -0
  9. package/src/DOM/IRenderCycle.ts +9 -0
  10. package/src/DOM/Key.ts +1 -0
  11. package/src/DOM/Node.ts +472 -0
  12. package/src/DOM/Registry.ts +53 -0
  13. package/src/creo.ts +134 -0
  14. package/src/data-structures/assert/assert.ts +12 -0
  15. package/src/data-structures/indexed-map/IndexedMap.ts +281 -0
  16. package/src/data-structures/linked-map/LinkedMap.spec.ts +67 -0
  17. package/src/data-structures/linked-map/LinkedMap.ts +198 -0
  18. package/src/data-structures/list/List.spec.ts +181 -0
  19. package/src/data-structures/list/List.ts +195 -0
  20. package/src/data-structures/maybe/Maybe.ts +25 -0
  21. package/src/data-structures/null/null.ts +3 -0
  22. package/src/{tools/isRecordLike.spec.ts → data-structures/record/IsRecordLike.spec.ts} +1 -1
  23. package/src/{tools/isRecordLike.ts → data-structures/record/IsRecordLike.ts} +1 -1
  24. package/src/{record/record.spec.ts → data-structures/record/Record.spec.ts} +96 -2
  25. package/src/data-structures/record/Record.ts +145 -0
  26. package/src/data-structures/shalllowEqual/shallowEqual.ts +26 -0
  27. package/src/data-structures/simpleKey/simpleKey.ts +8 -0
  28. package/src/data-structures/wildcard/wildcard.ts +1 -0
  29. package/src/examples/SimpleTodoList/SimpleTodoList.ts +53 -0
  30. package/src/globals.d.ts +1 -0
  31. package/src/main.ts +22 -11
  32. package/src/style.css +24 -79
  33. package/src/ui/html/Block.ts +10 -0
  34. package/src/ui/html/Button.ts +12 -0
  35. package/src/ui/html/HStack.ts +10 -0
  36. package/src/ui/html/Inline.ts +12 -0
  37. package/src/ui/html/List.ts +10 -0
  38. package/src/ui/html/Text.ts +9 -0
  39. package/src/ui/html/VStack.ts +11 -0
  40. package/tsconfig.json +2 -2
  41. package/vite.config.js +10 -0
  42. package/bun.lockb +0 -0
  43. package/src/record/record.ts +0 -101
  44. package/src/tools/optional.ts +0 -25
  45. package/src/ui/component.ts +0 -1
  46. package/src/ui/prop.ts +0 -13
  47. package/src/ui/state.ts +0 -0
  48. /package/src/{ui/index.ts → examples/simple.ts} +0 -0
@@ -1,101 +0,0 @@
1
- /**
2
- * Ideas:
3
- * [x] didUpdate support
4
- * [x] Proxy proxifies all children as well
5
- * [ ] Keep track on updates, until there are no users on the old state
6
- * [ ] Support symbol iterator
7
- * [ ] Add js dispose tracker to automatically close listeners
8
- */
9
-
10
- import { isRecordLike } from "../tools/isRecordLike";
11
-
12
- type Record<T extends object> = T;
13
- type Wildcard = any;
14
- type RecordDidChangeListener<T extends object> = (record: Record<T>) => void;
15
-
16
- const didUpdateMap: WeakMap<
17
- Record<Wildcard>,
18
- Set<RecordDidChangeListener<Wildcard>>
19
- > = new WeakMap();
20
-
21
- const scheduledUpdatesNotifiers: Set<Record<Wildcard>> = new Set();
22
- let shouldScheduleMicrotask = true;
23
- function queuedNotifier() {
24
- shouldScheduleMicrotask = true;
25
- scheduledUpdatesNotifiers.forEach((record) => {
26
- const listeners = didUpdateMap.get(record);
27
- if (!listeners) {
28
- return;
29
- }
30
- listeners.forEach((listener) => {
31
- listener(record);
32
- });
33
- });
34
- }
35
- function recordDidUpdate<T extends object>(record: Record<T>) {
36
- scheduledUpdatesNotifiers.add(record);
37
- shouldScheduleMicrotask && queueMicrotask(queuedNotifier);
38
- shouldScheduleMicrotask = false;
39
- }
40
-
41
- function creoRecord<TNode extends object, T extends object>(
42
- rootRecord: Record<TNode>,
43
- value: T,
44
- ): Record<T> {
45
- return new Proxy(value, {
46
- // @ts-ignore we override `get` to improve typing
47
- get<K extends keyof T>(target: T, property: K): T[K] {
48
- const val = target[property];
49
- if (isRecordLike(val)) {
50
- // @ts-ignore we proxify all nested objects / arrays to ensure correct behaviour
51
- return creoRecord(rootRecord, val);
52
- }
53
- return val;
54
- },
55
- // @ts-ignore
56
- set<K, TNewValue>(target: T, property: K, newValue: TNewValue) {
57
- // @ts-ignore
58
- target[property] = newValue;
59
- recordDidUpdate(rootRecord);
60
- return true;
61
- },
62
- });
63
- }
64
-
65
- export function record<TNode extends object>(value: TNode): Record<TNode> {
66
- const rootRecord = new Proxy(value, {
67
- // @ts-ignore we override `get` to improve typing
68
- get<K extends keyof T>(target: T, property: K): T[K] {
69
- const val = target[property];
70
- if (isRecordLike(val)) {
71
- // @ts-ignore we proxify all nested objects / arrays to ensure correct behaviour
72
- return creoRecord(rootRecord, val);
73
- }
74
- return val;
75
- },
76
- // @ts-ignore
77
- set<K, TNewValue>(target: T, property: K, newValue: TNewValue) {
78
- // @ts-ignore
79
- target[property] = newValue;
80
- recordDidUpdate(rootRecord);
81
- return true;
82
- },
83
- });
84
- didUpdateMap.set(rootRecord, new Set());
85
- return rootRecord;
86
- }
87
-
88
- export function onDidUpdate<T extends object>(
89
- record: Record<T>,
90
- listener: (record: Record<T>) => void,
91
- ): () => void {
92
- const listeners = didUpdateMap.get(record);
93
- if (!listeners) {
94
- // Safe-guard: Essentialy this path cannot happen
95
- throw new TypeError(`Record ${record} was created without listener`);
96
- }
97
- listeners.add(listener);
98
- return function unsubscribe() {
99
- listeners.delete(listener);
100
- };
101
- }
@@ -1,25 +0,0 @@
1
- export type None = null;
2
- export type Just<T> = T;
3
- export type Optional<T> = Just<T> | None;
4
-
5
- export function isJust<T>(v: Optional<T>): v is Just<T> {
6
- return v != null;
7
- }
8
-
9
- export function isNone<T>(v: Optional<T>): v is None {
10
- return v == null;
11
- }
12
-
13
- export function unwrap<T>(v: Optional<T>): Just<T> {
14
- if (isJust(v)) {
15
- return v;
16
- }
17
- throw new TypeError("Optional is none");
18
- }
19
-
20
- export function orDefault<T, K>(v: Optional<T>, alternative: K) {
21
- if (isJust(v)) {
22
- return v;
23
- }
24
- return alternative;
25
- }
@@ -1 +0,0 @@
1
- function
package/src/ui/prop.ts DELETED
@@ -1,13 +0,0 @@
1
- export const $prop = {
2
- ofString: () => {
3
- return {
4
-
5
- }
6
- },
7
- ofNumber: (prop: number) => {
8
-
9
- },
10
- of<T>: (prop: T) => {
11
-
12
- }
13
- }
package/src/ui/state.ts DELETED
File without changes
File without changes