You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<b>purify.js</b> is a 1.0kB <i>(minified, gzipped)</i> JavaScript UI building library that encourages the usage of pure JavaScript and DOM, while providing a thin layer of abstraction for the annoying parts for better DX <i>(developer experience)</i>. 🚀
17
17
</p>
18
18
19
-
# Features 🌟
19
+
# Features 🌟🚀
20
20
21
21
- 🔥 **Keeps you close to the DOM.**
22
22
- ✍️ `HTMLElement` builder allows you to differentiate between attributes and properties.
@@ -33,13 +33,13 @@
33
33
34
34
---
35
35
36
-
## Compare 📏
36
+
## Compare 📏⚖️
37
37
38
-
### Size ⚡
38
+
### Size ⚡📊
39
39
40
40
| Library | .min.js | .min.js.gz |
41
41
| --------------- | ------- | ---------- |
42
-
|**purify.js**| 2.3kB| 1.0kB |
42
+
|**purify.js**| 2.2kB| 1.0kB |
43
43
| Preact 10.19.3 | 11.2kB | 4.5kB |
44
44
| Solid 1.8.12 | 23kB | 8.1kB |
45
45
| jQuery 3.7.1 | 85.1kB | 29.7kB |
@@ -49,7 +49,7 @@
49
49
50
50
---
51
51
52
-
## Installation 🍙
52
+
## Installation 📦🍙
53
53
54
54
To install **purify.js**, follow the [jsr.io/@purifyjs/core](https://jsr.io/@purifyjs/core).
- Right now, when a `Signal` is connected to DOM via `Builder`, we update all of the children of the `ParentNode` with
218
+
`ParentNode.prototype.replaceChildren()`.
219
+
220
+
This is obviously not that great, previously at `0.1.6` I was using a `<div>` element with the style `display:contents` to wrap a rendered
221
+
`Signal` on the DOM. This was also allowing me to follow it's lifecyle via `connectedCallback`/`disconnectedCallback` which was allowing
222
+
me to follow or unfollow the `Signal`, making cleanup easier.
223
+
224
+
But since we wrap it with an `HTMLElement` it was causing problems with CSS selectors, since now each `Signal` is an `HTMLElement` on the
225
+
DOM.
226
+
227
+
So at `0.2.0` I made it so that all children of the `ParentNode` updates when a `Signal` child changes. Tho this issue can be escaped by
228
+
seperating things while writing the code. Or make use of things like `.replaceChild()`. Since all support `Signal`(s) now.
229
+
230
+
But to solve the core of this issue JS needs a real `DocumentFragment` with persistent children.
231
+
232
+
This proposal might solve this issue:
233
+
[DOM#739 Proposal: a DocumentFragment whose nodes do not get removed once inserted](https://github.com/whatwg/dom/issues/736).
234
+
235
+
In the puroposal they purpose on making the fragment undetactable with `childNodes` or `children` which I'm against and don't like at all.
236
+
`DocumentFragment` should be a `ParentNode` should have it's own children, and can be `ChildNode` of other `ParentNode`. Normal hierarchy,
237
+
no trasparency other than CSS.
238
+
239
+
But it's a good start, but just by having a real, working as intended, `DocumentFragment` we are not done.
240
+
241
+
Which brings be to the next point.
242
+
243
+
- We also need a native, sync and easy to use way to follow lifecycle of any DOM `ChildNode`, or at least all `Element` and this new
244
+
persistent `DocumentFragment`. Because without a lifecycle feature we can't bind a `Signal` to the DOM, start, stop/cleanup them
245
+
automatically.
246
+
247
+
An issue is open here [DOM#533 Make it possible to observe connected-ness of a node](https://github.com/whatwg/dom/issues/533).
248
+
249
+
Since DOM already has a sync way to follow lifecycle of custom `HTMLElement`(s). Since this is the only way, at this time we heavily relay
250
+
on that. Currently we use auto created Custom Elements via `tags` proxy and `WithLifecycle``HTMLElement` mixin. And allow `Signal`
251
+
related things only on those elements.
252
+
253
+
- If this feature above doesn't come sooner we also keep an eye of this other proposal which has more attraction:
254
+
[webcomponents#1029 Proposal: Custom attributes for all elements, enhancements for more complex use cases](https://github.com/WICG/webcomponents/issues/1029)
255
+
256
+
This proposal doesn't fix the issue with `DocumentFragment`(s), but improves and makes `HTMLElement` based lifecycles more modular and DX
257
+
friendly.
258
+
259
+
Right now, we have a mixing function called `WithLifecycle` which can be used like:
260
+
```ts
261
+
WithLifecycle(HTMLElement); // or
262
+
WithLifecycle(HTMLDivElement);
263
+
```
264
+
It adds a lifecycle function called `$effect()` to any `HTMLElement` type. Which can later be extended by a custom element like
265
+
```ts
266
+
classMyElementextendsWithLifecycle(HTMLElement)
267
+
```
268
+
Allowing you to create your own custom `HTMLElement` type with lifecycle. the `tags` proxy also uses `WithLifecycle` in combination with
269
+
`Builder` internally. so when you do `tags.div()` you are actually getting a `<divis="pure-div">` with a lifecycle. _But the `[is]`
270
+
attribute is not visible in the DOM since this element created by JS, not HTML_.
271
+
272
+
Anyway since this method requires you to decide if something is an element with lifecycle ahead of time, and also requires use to create
273
+
`pure-*` variant of native HTMLElement types in order to make them have lifecycle, it's kinda a lot. It makes sense. But it's kind of a
274
+
lot.
275
+
276
+
So this new custom attributes proposal can let us have lifecycle on any `Element` easily by simily adding an attribute to it. And this can
277
+
reshape a big portion of this codebase. And would make things connected to lifecyle of the `Element` more visible in the DOM. Which is
0 commit comments