ajo 0.0.8 → 0.0.9

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/index.cjs CHANGED
@@ -104,8 +104,7 @@ const Fragment = ({ children }) => children, h = (nodeName, props, ...children)
104
104
  (cleaners.get(host) ?? cleaners.set(host, /* @__PURE__ */ new Set())).add(cleaner);
105
105
  }, clx = (o) => keys(o).filter((k) => o[k]).join(" ") || null, stx = (o) => entries(o).map((t) => t.join(":")).join(";") || null, keb = (o) => keys(o).reduce((r, k) => (r[k.replace(search, replace).toLowerCase()] = o[k], r), {});
106
106
  const wm = () => {
107
- const instance = /* @__PURE__ */ new WeakMap();
108
- const { set } = instance;
107
+ const instance = /* @__PURE__ */ new WeakMap(), { set } = instance;
109
108
  instance.set = (key, value) => (set.call(instance, key, value), value);
110
109
  return instance;
111
110
  }, throwTypeError = (name, value, expected) => {
package/index.js CHANGED
@@ -96,8 +96,7 @@ export const
96
96
 
97
97
  const
98
98
  wm = () => {
99
- const instance = new WeakMap
100
- const { set } = instance
99
+ const instance = new WeakMap, { set } = instance
101
100
  instance.set = (key, value) => (set.call(instance, key, value), value)
102
101
  return instance
103
102
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajo",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "ajo is a JavaScript view library for building user interfaces",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -8,13 +8,16 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./index.js",
11
- "require": "./index.cjs"
11
+ "require": "./index.cjs",
12
+ "browser": "./index.min.js"
12
13
  }
13
14
  },
14
15
  "scripts": {
15
- "build": "esbuild --format=cjs --out-extension:.js=.cjs --outdir=. index.js",
16
- "test": "uvu",
17
- "release": "npm run build && npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
16
+ "build": "npm run build:require && npm run build:browser",
17
+ "build:require": "esbuild --format=cjs --out-extension:.js=.cjs --outdir=. index.js",
18
+ "build:browser": "esbuild --format=iife --out-extension:.js=.min.js --outdir=. --global-name=ajo --minify index.js",
19
+ "release": "npm run build && npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish",
20
+ "test": "uvu"
18
21
  },
19
22
  "repository": "cristianfalcone/ajo",
20
23
  "author": "Cristian Falcone",
package/readme.md CHANGED
@@ -1,15 +1,13 @@
1
1
  # ajo
2
2
  ajo is a JavaScript view library for building user interfaces
3
3
 
4
+ ## Install
5
+
4
6
  ```sh
5
7
  npm install ajo
6
8
  ```
7
9
 
8
- ## Incremental DOM
9
- To keep the UI in sync, ajo uses a technique called incremental DOM.
10
- It is a way to build UI components without the need to keep previous virtual DOM in memory.
11
- Instead, generated virtual DOM is diffed against the actual DOM, and changes are applied along the way.
12
- This reduces memory usage and makes ajo code more simple and concise. As a result, ajo is easy to read and maintain, but lacks perfomance oportunities that diffing two virtual DOM trees can provide.
10
+ ## Render JSX to a DOM element
13
11
 
14
12
  ```jsx
15
13
  /** @jsx h */
@@ -17,13 +15,10 @@ import { h, render } from 'ajo'
17
15
 
18
16
  document.body.innerHTML = '<div>Hello World</div>'
19
17
 
20
- render(document.body, <div>Goodbye World</div>)
18
+ render(<div>Goodbye World</div>, document.body)
21
19
  ```
22
20
 
23
- ## Stateless components
24
- As a way to reuse markup snipets, ajo uses simple synchroneous functions that return virtual DOM.
25
- This type of components are ment to be "consumers" of data.
26
- No state is preserved between invocations, so generated virtual DOM should rely exclusively on function's arguments.
21
+ ## Stateless Component
27
22
 
28
23
  ```jsx
29
24
  /** @jsx h */
@@ -31,20 +26,17 @@ import { h, render } from 'ajo'
31
26
 
32
27
  const Greet = ({ name }) => <div>Hello {name}</div>
33
28
 
34
- render(document.body, <Greet name="World" />)
29
+ render(<Greet name="World" />, document.body)
35
30
  ```
36
31
 
37
- ## Stateful components
38
- Since ajo does not store previous virtual DOM, stateful components rely on a DOM node to preserve its state between UI updates.
39
- This DOM node is called a host node (similar to a Web Component host node).
40
- State is declared in a generator function local scope.
41
- Then ajo asociates the returned iterator with the host, and updates host children nodes each time, retrieving iterator's next value. Lifecycle of these components are closely related to its host nodes, and generator function provides a way to manage them.
32
+ ## Stateful Component
42
33
 
43
34
  ```jsx
44
35
  /** @jsx h */
45
- import { h, component, render, refresh } from 'ajo'
36
+ import { h, component, refresh, render } from 'ajo'
46
37
 
47
38
  const Counter = component(({ start = 0 }, host) => {
39
+
48
40
  let count = start
49
41
 
50
42
  const increment = () => {
@@ -58,5 +50,5 @@ const Counter = component(({ start = 0 }, host) => {
58
50
  </button>
59
51
  })
60
52
 
61
- render(document.body, <Counter start={1} />)
53
+ render(<Counter start={1} />, document.body)
62
54
  ```