@esportsplus/template 0.15.13 → 0.15.14

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.

Potentially problematic release.


This version of @esportsplus/template might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  import { effect } from '@esportsplus/reactivity';
2
2
  import { isArray, isFunction, isObject, isString } from '@esportsplus/utilities';
3
- import { onCleanup } from './slot.js';
3
+ import { ondisconnect } from './slot.js';
4
4
  import { className, raf, removeAttribute, setAttribute } from './utilities.js';
5
5
  import event from './event.js';
6
6
  let attributes = {}, delimiters = {
@@ -33,7 +33,7 @@ function set(element, value, name, wait = false) {
33
33
  }
34
34
  else {
35
35
  let id = ('e' + store(element)[key]++);
36
- onCleanup(element, effect(() => {
36
+ ondisconnect(element, effect(() => {
37
37
  let v = value(element);
38
38
  if (isArray(v)) {
39
39
  let last = v.length - 1;
package/build/event.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { defineProperty } from '@esportsplus/utilities';
3
- import { onCleanup } from './slot.js';
3
+ import { ondisconnect } from './slot.js';
4
4
  import { addEventListener, parentElement } from './utilities.js';
5
5
  let capture = new Set(['onblur', 'onfocus', 'onscroll']), controllers = new Map(), keys = {}, passive = new Set([
6
6
  'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel',
@@ -26,7 +26,7 @@ export default (element, event, listener) => {
26
26
  return;
27
27
  }
28
28
  else if (event === 'ondisconnect') {
29
- onCleanup(element, () => listener(element));
29
+ ondisconnect(element, () => listener(element));
30
30
  return;
31
31
  }
32
32
  else if (event === 'onrender') {
@@ -44,7 +44,7 @@ export default (element, event, listener) => {
44
44
  }
45
45
  if (controller) {
46
46
  controller.listeners++;
47
- onCleanup(element, () => {
47
+ ondisconnect(element, () => {
48
48
  if (--controller.listeners) {
49
49
  return;
50
50
  }
package/build/slot.d.ts CHANGED
@@ -15,7 +15,7 @@ declare class Slot {
15
15
  splice(start: number, stop?: number, ...groups: Elements[]): Elements[];
16
16
  unshift(...groups: Elements[]): number;
17
17
  }
18
- declare const onCleanup: (element: Element, fn: VoidFunction) => void;
18
+ declare const ondisconnect: (element: Element, fn: VoidFunction) => void;
19
19
  declare const _default: (marker: Element, value: unknown) => Slot;
20
20
  export default _default;
21
- export { onCleanup, Slot };
21
+ export { ondisconnect, Slot };
package/build/slot.js CHANGED
@@ -3,7 +3,8 @@ import { isArray, isFunction, isInstanceOf, isObject } from '@esportsplus/utilit
3
3
  import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants.js';
4
4
  import { hydrate } from './html/index.js';
5
5
  import { firstChild, nextSibling, nodeValue, raf, text } from './utilities.js';
6
- let cleanup = [], scheduled = false;
6
+ import queue from '@esportsplus/queue';
7
+ let cleanup = queue(), scheduled = false;
7
8
  function after(anchor, groups) {
8
9
  for (let i = 0, n = groups.length; i < n; i++) {
9
10
  let group = groups[i];
@@ -20,7 +21,7 @@ function remove(...groups) {
20
21
  for (let j = 0, o = group.length; j < o; j++) {
21
22
  let item = group[j];
22
23
  if (item[SLOT_CLEANUP]) {
23
- cleanup.push(...item[SLOT_CLEANUP]);
24
+ cleanup.add(item[SLOT_CLEANUP]);
24
25
  }
25
26
  item.remove();
26
27
  }
@@ -83,9 +84,11 @@ function schedule() {
83
84
  scheduled = true;
84
85
  raf.add(() => {
85
86
  try {
86
- let fn;
87
- while (fn = cleanup.pop()) {
88
- fn();
87
+ let fns;
88
+ while (fns = cleanup.next()) {
89
+ for (let i = 0, n = fns.length; i < n; i++) {
90
+ fns[i]();
91
+ }
89
92
  }
90
93
  }
91
94
  catch (e) { }
@@ -100,7 +103,7 @@ class Slot {
100
103
  nodes;
101
104
  text = null;
102
105
  constructor(marker) {
103
- onCleanup(marker, () => this.clear());
106
+ ondisconnect(marker, () => this.clear());
104
107
  this.marker = marker;
105
108
  this.nodes = [];
106
109
  }
@@ -137,7 +140,7 @@ class Slot {
137
140
  }
138
141
  render(input) {
139
142
  if (isFunction(input)) {
140
- onCleanup(this.marker, effect(() => {
143
+ ondisconnect(this.marker, effect(() => {
141
144
  let v = input();
142
145
  if (isFunction(v)) {
143
146
  root(() => this.render(v()));
@@ -181,10 +184,10 @@ class Slot {
181
184
  return this.nodes.unshift(...after(this.marker, groups));
182
185
  }
183
186
  }
184
- const onCleanup = (element, fn) => {
187
+ const ondisconnect = (element, fn) => {
185
188
  (element[SLOT_CLEANUP] ??= []).push(fn);
186
189
  };
187
190
  export default (marker, value) => {
188
191
  return new Slot(marker).render(value);
189
192
  };
190
- export { onCleanup, Slot };
193
+ export { ondisconnect, Slot };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
- "@esportsplus/reactivity": "^0.11.8",
5
- "@esportsplus/tasks": "^0.1.11",
4
+ "@esportsplus/queue": "^0.0.1",
5
+ "@esportsplus/reactivity": "^0.12.1",
6
+ "@esportsplus/tasks": "^0.2.0",
6
7
  "@esportsplus/utilities": "^0.21.1"
7
8
  },
8
9
  "devDependencies": {
@@ -13,7 +14,7 @@
13
14
  "private": false,
14
15
  "type": "module",
15
16
  "types": "./build/index.d.ts",
16
- "version": "0.15.13",
17
+ "version": "0.15.14",
17
18
  "scripts": {
18
19
  "build": "tsc && tsc-alias",
19
20
  "-": "-"
package/src/attributes.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { effect } from '@esportsplus/reactivity';
2
2
  import { isArray, isFunction, isObject, isString } from '@esportsplus/utilities';
3
- import { onCleanup } from './slot';
3
+ import { ondisconnect } from './slot';
4
4
  import { Attributes, Element } from './types';
5
5
  import { className, raf, removeAttribute, setAttribute } from './utilities';
6
6
  import event from './event';
@@ -42,7 +42,7 @@ function set(element: Element, value: unknown, name: string, wait = false) {
42
42
  else {
43
43
  let id = ('e' + store(element)[key]++);
44
44
 
45
- onCleanup(
45
+ ondisconnect(
46
46
  element,
47
47
  effect(() => {
48
48
  let v = (value as Function)(element);
package/src/event.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { root } from '@esportsplus/reactivity';
2
2
  import { defineProperty } from '@esportsplus/utilities';
3
- import { onCleanup } from './slot';
3
+ import { ondisconnect } from './slot';
4
4
  import { Element } from './types';
5
5
  import { addEventListener, parentElement } from './utilities';
6
6
 
@@ -43,7 +43,7 @@ export default (element: Element, event: `on${string}`, listener: Function): voi
43
43
  return;
44
44
  }
45
45
  else if (event === 'ondisconnect') {
46
- onCleanup(element, () => listener(element));
46
+ ondisconnect(element, () => listener(element));
47
47
  return;
48
48
  }
49
49
  else if (event === 'onrender') {
@@ -70,7 +70,7 @@ export default (element: Element, event: `on${string}`, listener: Function): voi
70
70
  if (controller) {
71
71
  controller.listeners++;
72
72
 
73
- onCleanup(element, () => {
73
+ ondisconnect(element, () => {
74
74
  if (--controller.listeners) {
75
75
  return;
76
76
  }
package/src/slot.ts CHANGED
@@ -4,9 +4,10 @@ import { RENDERABLE, RENDERABLE_REACTIVE, SLOT_CLEANUP } from './constants';
4
4
  import { hydrate } from './html';
5
5
  import { Element, Elements, RenderableReactive, RenderableTemplate } from './types';
6
6
  import { firstChild, nextSibling, nodeValue, raf, text } from './utilities'
7
+ import queue from '@esportsplus/queue';
7
8
 
8
9
 
9
- let cleanup: VoidFunction[] = [],
10
+ let cleanup = queue<VoidFunction[]>(),
10
11
  scheduled = false;
11
12
 
12
13
 
@@ -31,7 +32,7 @@ function remove(...groups: Elements[]) {
31
32
  let item = group[j];
32
33
 
33
34
  if (item[SLOT_CLEANUP]) {
34
- cleanup.push(...item[SLOT_CLEANUP]);
35
+ cleanup.add( item[SLOT_CLEANUP] );
35
36
  }
36
37
 
37
38
  item.remove();
@@ -112,10 +113,12 @@ function schedule() {
112
113
 
113
114
  raf.add(() => {
114
115
  try {
115
- let fn;
116
+ let fns;
116
117
 
117
- while (fn = cleanup.pop()) {
118
- fn();
118
+ while (fns = cleanup.next()) {
119
+ for (let i = 0, n = fns.length; i < n; i++) {
120
+ fns[i]();
121
+ }
119
122
  }
120
123
  }
121
124
  catch(e) { }
@@ -136,7 +139,7 @@ class Slot {
136
139
 
137
140
 
138
141
  constructor(marker: Element) {
139
- onCleanup(marker, () => this.clear());
142
+ ondisconnect(marker, () => this.clear());
140
143
 
141
144
  this.marker = marker;
142
145
  this.nodes = [];
@@ -190,7 +193,7 @@ class Slot {
190
193
 
191
194
  render(input: unknown) {
192
195
  if (isFunction(input)) {
193
- onCleanup(
196
+ ondisconnect(
194
197
  this.marker,
195
198
  effect(() => {
196
199
  let v = (input as Function)();
@@ -256,7 +259,7 @@ class Slot {
256
259
  }
257
260
 
258
261
 
259
- const onCleanup = (element: Element, fn: VoidFunction) => {
262
+ const ondisconnect = (element: Element, fn: VoidFunction) => {
260
263
  ( element[SLOT_CLEANUP] ??= [] ).push(fn);
261
264
  };
262
265
 
@@ -264,4 +267,4 @@ const onCleanup = (element: Element, fn: VoidFunction) => {
264
267
  export default (marker: Element, value: unknown) => {
265
268
  return new Slot(marker).render(value);
266
269
  };
267
- export { onCleanup, Slot };
270
+ export { ondisconnect, Slot };