aberdeen 0.0.14 → 0.0.16

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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  ISC License
2
2
 
3
- Copyright (c) 2021 Frank van Viegen
3
+ Copyright (c) 2021-2024 Frank van Viegen
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -1,6 +1,3 @@
1
- Aberdeen
2
- --------
3
-
4
1
  A TypeScript/JavaScript library for quickly building performant declarative user interfaces *without* the use of a virtual DOM.
5
2
 
6
3
  The key insight is the use of many small anonymous functions, that will automatically rerun when the underlying data changes. In order to trigger updates, that data should be encapsulated in any number of `Store` objects. They can hold anything, from simple values to deeply nested data structures, in which case user-interface functions can (automatically) subscribe to just the parts they depend upon.
@@ -10,5 +7,112 @@ The key insight is the use of many small anonymous functions, that will automati
10
7
 
11
8
  - It provides a flexible and simple to understand model for reactive user-interface building.
12
9
  - It allows you to express user-interfaces in plain JavaScript (or TypeScript) in an easy to read form, without (JSX-like) compilation steps.
13
- - It's fast, as it doesn't use a *virtual DOM* and only reruns small pieces of code in response to updated data.
14
- - It's lightweight, at less than 15kb when minimized.
10
+ - It's fast, as it doesn't use a *virtual DOM* and only reruns small pieces of code in response to updated data. It also makes displaying and updating sorted lists very easy and very fast.
11
+ - It's lightweight, at about 15kb minimized.
12
+
13
+
14
+ ## Examples
15
+
16
+ - [Tic-tac-toe demo](https://vanviegen.github.io/aberdeen/examples/tic-tac-toe/) - [Source](https://github.com/vanviegen/aberdeen/tree/master/examples/tic-tac-toe)
17
+ - [Input example demo](https://vanviegen.github.io/aberdeen/examples/input/) - [Source](https://github.com/vanviegen/aberdeen/tree/master/examples/input)
18
+
19
+
20
+ To get a quick impression of what Aberdeen code looks like, this is all of the JavaScript for the above Tic-tac-toe demo:
21
+
22
+ ```javascript
23
+ import {node, prop, mount, Store, text} from 'https://cdn.jsdelivr.net/npm/aberdeen/+esm';
24
+
25
+ const store = new Store({
26
+ squares: [],
27
+ turn: 'X',
28
+ history: [{}],
29
+ })
30
+
31
+ const drawSquare = (position) => {
32
+ node('button.square', () => {
33
+ let value = store.get('squares', position)
34
+ if (value) text(value)
35
+ else prop('click', () => fillSquare(position))
36
+ })
37
+ }
38
+
39
+ const drawBoard = () => {
40
+ for(let y=0; y<3; y++) {
41
+ node('div.board-row', () => {
42
+ for(let x=0; x<3; x++) {
43
+ drawSquare(y*3 + x)
44
+ }
45
+ })
46
+ }
47
+ }
48
+
49
+ const drawInfo = () => {
50
+ node('div', () => {
51
+ let winner = calculateWinner(store.get('squares'))
52
+ if (winner) {
53
+ text(`Winner: ${winner}`)
54
+ } else {
55
+ text(`Next player: ${store.get('turn')}`)
56
+ }
57
+ })
58
+ node('ol', () => {
59
+ store.onEach('history', item => {
60
+ node('li', () => {
61
+ node('button', () => {
62
+ text(item.index() ? `Go to move ${item.index()}` : `Go to game start`)
63
+ prop('click', () => {
64
+ store.set('historyPos', item.index())
65
+ store.set('squares', item.get())
66
+ })
67
+ })
68
+ })
69
+ })
70
+ })
71
+ }
72
+
73
+ const fillSquare = (position) => {
74
+ // If there's already a winner, don't allow a new square to be filled
75
+ if (calculateWinner(store.get('squares'))) return
76
+
77
+ // Fill the square
78
+ store.set('squares', position, store.get('turn'))
79
+
80
+ // Next player's turn
81
+ store.set('turn', store.get('turn')==='X' ? 'O' : 'X')
82
+
83
+ if (store.get('historyPos') != null) {
84
+ // Truncate everything after history pos
85
+ store.set('history', store.get('history').slice(0,store.get('historyPos')+1))
86
+ // Stop 'time traveling'
87
+ store.delete('historyPos')
88
+ }
89
+
90
+ // Append the current squares-state to the history array
91
+ store.push('history', store.get('squares'))
92
+ }
93
+
94
+ const calculateWinner = (squares) => {
95
+ const lines = [
96
+ [0, 1, 2], [3, 4, 5], [6, 7, 8], // horizontal
97
+ [0, 3, 6], [1, 4, 7], [2, 5, 8], // vertical
98
+ [0, 4, 8], [2, 4, 6] // diagonal
99
+ ];
100
+ for (const [a, b, c] of lines) {
101
+ if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
102
+ return squares[a];
103
+ }
104
+ }
105
+ }
106
+
107
+ mount(document.body, () => {
108
+ node('div.game', () => {
109
+ node('div.game-board', drawBoard)
110
+ node('div.game-info', drawInfo)
111
+ })
112
+ })
113
+ ```
114
+
115
+
116
+ ## Reference documentation
117
+
118
+ https://vanviegen.github.io/aberdeen/
@@ -2,7 +2,7 @@ interface QueueRunner {
2
2
  queueOrder: number;
3
3
  queueRun(): void;
4
4
  }
5
- declare type SortKeyType = number | string | Array<number | string>;
5
+ type SortKeyType = number | string | Array<number | string>;
6
6
  interface Observer {
7
7
  onChange(index: any, newData: DatumType, oldData: DatumType): void;
8
8
  }
@@ -57,7 +57,7 @@ declare class OnEachItemScope extends Scope {
57
57
  queueRun(): void;
58
58
  update(): void;
59
59
  }
60
- declare type DatumType = string | number | Function | boolean | null | undefined | ObsMap | ObsArray;
60
+ type DatumType = string | number | Function | boolean | null | undefined | ObsMap | ObsArray;
61
61
  declare abstract class ObsCollection {
62
62
  observers: Map<any, Set<Observer>>;
63
63
  addObserver(index: any, observer: Observer): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aberdeen",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A TypeScript/JavaScript library for quickly building performant declarative user interfaces without the use of a virtual DOM.",
5
5
  "main": "dist/aberdeen.js",
6
6
  "types": "dist/aberdeen.d.js",
@@ -16,12 +16,12 @@
16
16
  "author": "Frank van Viegen",
17
17
  "license": "ISC",
18
18
  "devDependencies": {
19
+ "fast-equals": "^2.0.4",
19
20
  "mocha": "^9.1.3",
20
21
  "nyc": "^15.0.1",
21
22
  "terser": "^4.6.13",
22
- "typedoc": "^0.22.10",
23
- "typescript": "^4.9.5",
24
- "fast-equals": "^2.0.4"
23
+ "typedoc": "^0.23.28",
24
+ "typescript": "^4.9.5"
25
25
  },
26
26
  "nyc": {
27
27
  "reporter": [
@@ -37,7 +37,5 @@
37
37
  },
38
38
  "files": [
39
39
  "dist"
40
- ],
41
- "dependencies": {
42
- }
40
+ ]
43
41
  }