@libeilong/mobx
Advanced tools
+91
-90
@@ -1,11 +0,11 @@ | ||
| import { extendObservable as F, makeObservable as u, observable as n, action as c, computed as g } from "mobx"; | ||
| import m from "react"; | ||
| import { Observer as T } from "mobx-react-lite"; | ||
| function N(t, e) { | ||
| const i = {}, r = Object.keys(e); | ||
| for (const s of r) | ||
| s in t ? t[s] = e[s] : i[s] = e[s]; | ||
| Object.keys(i).length > 0 && F(t, i); | ||
| import { extendObservable as O, makeObservable as d, observable as r, action as f, computed as y } from "mobx"; | ||
| import F from "react"; | ||
| import { Observer as L } from "mobx-react-lite"; | ||
| function j(t, e) { | ||
| const i = {}, n = Object.keys(e); | ||
| for (const o of n) | ||
| o in t ? t[o] = e[o] : i[o] = e[o]; | ||
| Object.keys(i).length > 0 && O(t, i); | ||
| } | ||
| function k(t = {}) { | ||
| function E(t = {}) { | ||
| return (e) => { | ||
@@ -18,9 +18,9 @@ e.prototype._modelOptions = { | ||
| } | ||
| function b(t) { | ||
| function v(t) { | ||
| return typeof t == "function" ? t.prototype._modelOptions || {} : t && typeof t == "object" ? t._modelOptions || {} : {}; | ||
| } | ||
| var p = /* @__PURE__ */ ((t) => (t.OneToMany = "OneToMany", t.ManyToOne = "ManyToOne", t.OneToOne = "OneToOne", t.ManyToMany = "ManyToMany", t))(p || {}); | ||
| function f(t, e) { | ||
| return function(i, r) { | ||
| i.constructor._relations || (i.constructor._relations = {}), i.constructor._relations[r] = { | ||
| var m = /* @__PURE__ */ ((t) => (t.OneToMany = "OneToMany", t.ManyToOne = "ManyToOne", t.OneToOne = "OneToOne", t.ManyToMany = "ManyToMany", t))(m || {}); | ||
| function g(t, e) { | ||
| return function(i, n) { | ||
| i.constructor._relations || (i.constructor._relations = {}), i.constructor._relations[n] = { | ||
| type: t, | ||
@@ -31,41 +31,42 @@ modelClass: e | ||
| } | ||
| function E(t) { | ||
| return f("OneToMany", t); | ||
| } | ||
| function S(t) { | ||
| return f("ManyToOne", t); | ||
| return g("OneToMany", t); | ||
| } | ||
| function j(t) { | ||
| return f("OneToOne", t); | ||
| } | ||
| function D(t) { | ||
| return f("ManyToMany", t); | ||
| return g("ManyToOne", t); | ||
| } | ||
| function L(t) { | ||
| function R(t) { | ||
| return g("OneToOne", t); | ||
| } | ||
| function _(t) { | ||
| return g("ManyToMany", t); | ||
| } | ||
| function w(t) { | ||
| return typeof t == "function" ? t._relations || {} : t.constructor._relations || {}; | ||
| } | ||
| function R(t, e) { | ||
| const i = L(t), r = Object.keys(e); | ||
| for (const s of r) { | ||
| const a = i[s]; | ||
| if (a) { | ||
| const { primaryKey: l, createInstance: h } = b(a.modelClass); | ||
| if (!l) continue; | ||
| if ([p.ManyToMany, p.OneToMany].includes(a.type)) { | ||
| function A(t, e) { | ||
| const i = w(t), n = {}, o = Object.keys(e); | ||
| for (const s of o) { | ||
| const l = i[s]; | ||
| if (l) { | ||
| const { primaryKey: h, createInstance: u } = v(l.modelClass); | ||
| if (!h) continue; | ||
| if ([m.ManyToMany, m.OneToMany].includes(l.type)) { | ||
| if (!Array.isArray(e[s])) | ||
| throw new Error(`Expected an array for relation ${s.toString()}, but got ${typeof e[s]}`); | ||
| t[s] = e[s].map((o) => { | ||
| const d = typeof o == "object" ? o : { [l]: o }, y = t[s]?.find((O) => O[l] === d[l]); | ||
| return y || (h ? h(d) : new a.modelClass(d)); | ||
| const c = e[s].map((a) => { | ||
| const p = typeof a == "object" ? a : { [h]: a }, M = t[s]?.find((b) => b[h] === p[h]); | ||
| return M || (u ? u(p) : new l.modelClass(p)); | ||
| }); | ||
| s in t ? t[s] = c : n[s] = c; | ||
| } else { | ||
| const o = typeof e[s] == "object" ? e[s] : { [l]: e[s] }; | ||
| t[s] = h ? h(o) : new a.modelClass(o); | ||
| const c = typeof e[s] == "object" ? e[s] : { [h]: e[s] }, a = u ? u(c) : new l.modelClass(c); | ||
| s in t ? t[s] = a : n[s] = a; | ||
| } | ||
| } else | ||
| t[s] = e[s]; | ||
| s in t ? t[s] = e[s] : n[s] = e[s]; | ||
| } | ||
| return t; | ||
| return Object.keys(n).length > 0 && O(t, n), t; | ||
| } | ||
| class _ { | ||
| class z { | ||
| initCount = 60; | ||
@@ -75,5 +76,5 @@ defaultText = "获取验证码"; | ||
| constructor(e = {}) { | ||
| this.initCount = e.initCount ?? 60, this.defaultText = e.defaultText ?? "获取验证码", this.countTemplate = e.countTemplate ?? "{{count}}s", this.count = this.initCount, u(this, { | ||
| count: n, | ||
| isRunning: n | ||
| this.initCount = e.initCount ?? 60, this.defaultText = e.defaultText ?? "获取验证码", this.countTemplate = e.countTemplate ?? "{{count}}s", this.count = this.initCount, d(this, { | ||
| count: r, | ||
| isRunning: r | ||
| }); | ||
@@ -97,4 +98,4 @@ } | ||
| } | ||
| class w { | ||
| createElement = (e, i) => m.createElement( | ||
| class x { | ||
| createElement = (e, i) => F.createElement( | ||
| "div", | ||
@@ -117,15 +118,15 @@ { | ||
| } | ||
| class M { | ||
| constructor(e = new w()) { | ||
| this.adapter = e, u(this, { | ||
| list: n, | ||
| hasMore: n, | ||
| listLoading: n, | ||
| paging: n, | ||
| err: n, | ||
| notData: g, | ||
| state: g, | ||
| stateWidget: g, | ||
| fetch: c, | ||
| reset: c | ||
| class T { | ||
| constructor(e = new x()) { | ||
| this.adapter = e, d(this, { | ||
| list: r, | ||
| hasMore: r, | ||
| listLoading: r, | ||
| paging: r, | ||
| err: r, | ||
| notData: y, | ||
| state: y, | ||
| stateWidget: y, | ||
| fetch: f, | ||
| reset: f | ||
| }); | ||
@@ -142,3 +143,3 @@ } | ||
| paging = { | ||
| pageNumber: M.startPageNumber, | ||
| pageNumber: T.startPageNumber, | ||
| pageSize: 10, | ||
@@ -154,3 +155,3 @@ total: 0 | ||
| get stateWidget() { | ||
| return m.createElement(T, {}, () => { | ||
| return F.createElement(L, {}, () => { | ||
| switch (this.state) { | ||
@@ -178,4 +179,4 @@ case 2: | ||
| this.err = void 0, this.listLoading = !0, this.onFirstFetch && (await this.onFirstFetch(), delete this.onFirstFetch); | ||
| const { list: i, total: r } = await this.fetchList(); | ||
| this.paging.pageNumber === 1 ? this.list = i : this.list.push(...i), r ? (this.paging.total = r, this.list.length >= r && (this.hasMore = !1)) : i.length < this.paging.pageSize && (this.hasMore = !1), this.paging.pageNumber++; | ||
| const { list: i, total: n } = await this.fetchList(); | ||
| this.paging.pageNumber === 1 ? this.list = i : this.list.push(...i), n ? (this.paging.total = n, this.list.length >= n && (this.hasMore = !1)) : i.length < this.paging.pageSize && (this.hasMore = !1), this.paging.pageNumber++; | ||
| } catch (i) { | ||
@@ -191,8 +192,8 @@ this.err = i, console.log(i); | ||
| } | ||
| class z { | ||
| class P { | ||
| constructor() { | ||
| u(this, { | ||
| loading: n, | ||
| result: n, | ||
| firstFetch: n | ||
| d(this, { | ||
| loading: r, | ||
| result: r, | ||
| firstFetch: r | ||
| }); | ||
@@ -217,11 +218,11 @@ } | ||
| } | ||
| class A { | ||
| class I { | ||
| constructor() { | ||
| u(this, { | ||
| list: n, | ||
| loading: n, | ||
| paging: n, | ||
| total: n, | ||
| fetch: c, | ||
| reset: c | ||
| d(this, { | ||
| list: r, | ||
| loading: r, | ||
| paging: r, | ||
| total: r, | ||
| fetch: f, | ||
| reset: f | ||
| }); | ||
@@ -246,6 +247,6 @@ } | ||
| this.loading = !0, this.onFirstFetch && (await this.onFirstFetch(), delete this.onFirstFetch); | ||
| const { list: r, total: s } = await this.fetchList(); | ||
| this.list = r || [], this.total = s || 0; | ||
| } catch (r) { | ||
| console.log(r); | ||
| const { list: n, total: o } = await this.fetchList(); | ||
| this.list = n || [], this.total = o || 0; | ||
| } catch (n) { | ||
| console.log(n); | ||
| } finally { | ||
@@ -260,14 +261,14 @@ this.loading = !1; | ||
| export { | ||
| w as BaseFooterListAdapter, | ||
| _ as CountDownStore, | ||
| M as ListStore, | ||
| D as ManyToMany, | ||
| S as ManyToOne, | ||
| k as Model, | ||
| E as OneToMany, | ||
| j as OneToOne, | ||
| z as ResultStore, | ||
| A as TableListStore, | ||
| N as assignMobx, | ||
| R as assignModel | ||
| x as BaseFooterListAdapter, | ||
| z as CountDownStore, | ||
| T as ListStore, | ||
| _ as ManyToMany, | ||
| D as ManyToOne, | ||
| E as Model, | ||
| S as OneToMany, | ||
| R as OneToOne, | ||
| P as ResultStore, | ||
| I as TableListStore, | ||
| j as assignMobx, | ||
| A as assignModel | ||
| }; |
+1
-1
| { | ||
| "name": "@libeilong/mobx", | ||
| "version": "0.4.1", | ||
| "version": "0.4.2", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
101997
0.13%1757
0.06%