cradova 3.3.11 → 3.3.12

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/dist/index.js CHANGED
@@ -62,18 +62,18 @@ function loop(datalist, component) {
62
62
  }
63
63
  return Array.isArray(datalist) ? datalist.map(component) : undefined;
64
64
  }
65
- function useState(initialValue, Comp2) {
65
+ function useState(newState, Comp2) {
66
66
  Comp2._state_index += 1;
67
67
  const idx = Comp2._state_index;
68
68
  if (!Comp2._state_track[idx]) {
69
- Comp2._roll_state(initialValue, idx);
69
+ Comp2._state[idx] = newState;
70
70
  Comp2._state_track[idx] = true;
71
71
  }
72
- function setState(newState) {
73
- Comp2._roll_state(newState, idx);
72
+ function setState(newState2) {
73
+ Comp2._state[idx] = newState2;
74
74
  Comp2.recall();
75
75
  }
76
- return [Comp2._roll_state(null, idx, true), setState];
76
+ return [Comp2._state[idx], setState];
77
77
  }
78
78
  function useEffect(effect, Comp2) {
79
79
  Comp2._effect(effect);
@@ -250,7 +250,9 @@ class Comp {
250
250
  constructor(component) {
251
251
  this.component = component.bind(this);
252
252
  CradovaEvent.addBeforeMountActive(() => {
253
- this.published = false;
253
+ this._state_index = 0;
254
+ this._state_track = {};
255
+ this._state = [];
254
256
  });
255
257
  }
256
258
  preRender() {
@@ -274,21 +276,9 @@ class Comp {
274
276
  return this.preRendered;
275
277
  }
276
278
  }
277
- instance() {
278
- return this.reference.current("html");
279
- }
280
279
  _setExtra(Extra) {
281
280
  this.Signal = Extra;
282
281
  }
283
- _roll_state(data, idx, get = false) {
284
- if (!get) {
285
- if (idx !== 0) {
286
- this._state[idx - 1] = undefined;
287
- }
288
- this._state[idx] = data;
289
- }
290
- return this._state[idx];
291
- }
292
282
  _effect(fn) {
293
283
  if (!this.rendered) {
294
284
  this.effects.push(fn.bind(this));
@@ -333,6 +323,11 @@ class Comp {
333
323
  this.published = true;
334
324
  this.reference._appendDomForce("html", html);
335
325
  CradovaEvent.dispatchEvent("afterMount");
326
+ (async () => {
327
+ if (!document.contains(html)) {
328
+ this.rendered = false;
329
+ }
330
+ })();
336
331
  } else {
337
332
  console.error(" \u2718 Cradova err : Invalid html, got - " + html);
338
333
  }
@@ -5,8 +5,24 @@ import { type CradovaPageType, type promisedPage } from "./types";
5
5
  declare class cradovaEvent {
6
6
  private afterMount;
7
7
  private beforeMountActive;
8
+ /**
9
+ * add an event to an exhaustible list of events
10
+ * the events runs only once and removed.
11
+ * these event are call and removed once when when a comp is rendered to the dom
12
+ * @param callback
13
+ */
8
14
  addAfterMount(callback: () => void): Promise<void>;
15
+ /**
16
+ * add an event to a list of events
17
+ * the events runs many times.
18
+ * these event are called before a comp is rendered to the dom
19
+ * @param callback
20
+ */
9
21
  addBeforeMountActive(callback: () => void): Promise<void>;
22
+ /**
23
+ * Dispatch any event
24
+ * @param eventName
25
+ */
10
26
  dispatchEvent(eventName: "beforeMountActive" | "afterMount"): void;
11
27
  }
12
28
  export declare const CradovaEvent: cradovaEvent;
@@ -40,9 +56,7 @@ export declare class Comp<Prop extends Record<string, any> = any> {
40
56
  * @returns () => HTMLElement
41
57
  */
42
58
  render(): any;
43
- instance(): HTMLElement;
44
59
  _setExtra(Extra: createSignal<any>): void;
45
- _roll_state<S>(data: any, idx: number, get?: boolean): S;
46
60
  _effect(fn: () => Promise<void> | void): void;
47
61
  private effector;
48
62
  /**
@@ -208,7 +222,7 @@ export declare class Page {
208
222
  /**
209
223
  * this should be a cradova page component
210
224
  */
211
- _html: ((this: Page) => HTMLElement);
225
+ _html: (this: Page) => HTMLElement;
212
226
  private _template;
213
227
  private _callBack;
214
228
  private _deCallBack;
@@ -33,7 +33,7 @@ export declare const frag: (children: VJS_params_TYPE<HTMLElement>) => DocumentF
33
33
  * @param Comp
34
34
  * @returns [state, setState]
35
35
  */
36
- export declare function useState<S = unknown>(initialValue: S, Comp: Comp): [S, (newState: S) => void];
36
+ export declare function useState<S = unknown>(newState: S, Comp: Comp): [S, (newState: S) => void];
37
37
  /**
38
38
  * Cradova
39
39
  * ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cradova",
3
- "version": "3.3.11",
3
+ "version": "3.3.12",
4
4
  "description": "Build Powerful ⚡ Web Apps with Ease",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",