ddd-react 1.4.0 → 1.5.0

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.
@@ -23,7 +23,7 @@ export declare abstract class Component<P = {}, S = ComponentState, ContextValue
23
23
  notify(): void;
24
24
  onMount(): void | Promise<void>;
25
25
  onUnmount(): void | Promise<void>;
26
- onUpdate(): void | Promise<void>;
26
+ onUpdate(prevProps: P, prevState: S): void | Promise<void>;
27
27
  onWillUnmount(): void | Promise<void>;
28
28
  abstract render(): VDOMNode;
29
29
  get elements(): HTMLElement[];
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { D as c, e as g, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
1
+ import { D as c, e as v, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
2
2
  import { d as Ot, f as mt } from "./h-BbaMkkC7.mjs";
3
- function v(e, t) {
3
+ function g(e, t) {
4
4
  if (e === null || t === null || e === void 0 || t === void 0)
5
5
  return e === t;
6
6
  if (typeof e != typeof t)
@@ -14,7 +14,7 @@ function v(e, t) {
14
14
  if (e.length !== t.length)
15
15
  return !1;
16
16
  for (let r = 0; r < e.length; ++r)
17
- if (!v(e[r], t[r]))
17
+ if (!g(e[r], t[r]))
18
18
  return !1;
19
19
  return !0;
20
20
  }
@@ -32,7 +32,7 @@ function v(e, t) {
32
32
  return !1;
33
33
  for (let r = 0; r < n.length; ++r) {
34
34
  const s = n[r];
35
- if (!(s === "_owner" && e.$$typeof) && !v(e[s], t[s]))
35
+ if (!(s === "_owner" && e.$$typeof) && !g(e[s], t[s]))
36
36
  return !1;
37
37
  }
38
38
  return !0;
@@ -370,7 +370,7 @@ function ft(e, t = {}, n = {}, r = {}, s = null) {
370
370
  return l;
371
371
  }
372
372
  function R(e, t, n) {
373
- const r = g(e), s = g(t), o = e.el, i = x(r, s, D), f = n?.offset ?? 0;
373
+ const r = v(e), s = v(t), o = e.el, i = x(r, s, D), f = n?.offset ?? 0;
374
374
  for (const l of i)
375
375
  if (l.op === y.NOOP) {
376
376
  const { originalIndex: u, index: a } = l;
@@ -420,7 +420,7 @@ class k {
420
420
  }
421
421
  notify() {
422
422
  this.dependencies.forEach(({ consumer: t }) => {
423
- t.isMounted && t.updateContext() && t.patch();
423
+ t.isMounted && t.updateContext() && t.patch(t.props, t.state);
424
424
  });
425
425
  }
426
426
  onMount() {
@@ -429,14 +429,14 @@ class k {
429
429
  onUnmount() {
430
430
  return Promise.resolve();
431
431
  }
432
- onUpdate() {
432
+ onUpdate(t, n) {
433
433
  return Promise.resolve();
434
434
  }
435
435
  onWillUnmount() {
436
436
  return Promise.resolve();
437
437
  }
438
438
  get elements() {
439
- return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? g(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
439
+ return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? v(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
440
440
  }
441
441
  get firstElement() {
442
442
  return this.elements[0];
@@ -448,13 +448,14 @@ class k {
448
448
  const n = { ...this.props, ...t }, r = this.props;
449
449
  this.props = n;
450
450
  let s = this.updateContext();
451
- v(r, n) && !s || (ht(this) && this.notify(), this.patch());
451
+ g(r, n) && !s || (ht(this) && this.notify(), this.patch(r, this.state));
452
452
  }
453
453
  setState(t) {
454
+ let n = this.state;
454
455
  typeof t == "function" ? this.state = {
455
456
  ...this.state,
456
457
  ...t(this.state, this.props)
457
- } : this.state = { ...this.state, ...t }, this.patch();
458
+ } : this.state = { ...this.state, ...t }, this.patch(this.props, n);
458
459
  }
459
460
  mount(t, n = null) {
460
461
  if (this.isMounted)
@@ -466,11 +467,11 @@ class k {
466
467
  t.subscribedProvider = null;
467
468
  }), this.dependencies = [], this.vdom && p(this.vdom), E(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
468
469
  }
469
- patch() {
470
+ patch(t, n) {
470
471
  if (!this.isMounted || !this.hostEl || !this.vdom)
471
472
  return;
472
- const t = this.render();
473
- this.vdom = m(this.vdom, t, this.hostEl, this), E(() => this.onUpdate());
473
+ const r = this.render();
474
+ this.vdom = m(this.vdom, r, this.hostEl, this), E(() => this.onUpdate(t, n));
474
475
  }
475
476
  updateContext() {
476
477
  const t = Object.getPrototypeOf(this).constructor.contextType;
@@ -548,14 +549,14 @@ function bt(e = null) {
548
549
  current: e
549
550
  };
550
551
  }
551
- function gt(e, t) {
552
+ function vt(e, t) {
552
553
  const n = Array.isArray(e) ? e : [e];
553
554
  return I(n, t);
554
555
  }
555
556
  export {
556
557
  k as Component,
557
558
  yt as createContext,
558
- gt as createPortal,
559
+ vt as createPortal,
559
560
  bt as createRef,
560
561
  Ot as h,
561
562
  U as hFragment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",