@razaman2/reactive-view 0.0.8 → 0.0.10

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 razamvmt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 razamvmt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1 @@
1
- # reactive-view
1
+ # reactive-view
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
1
+ import { SetupContext, ComponentPublicInstance, WatchOptions, UnwrapRef } from 'vue';
2
2
 
3
3
  type SubscriptionItem = {
4
4
  name: string;
@@ -36,6 +36,7 @@ declare const _default: {
36
36
  model: {};
37
37
  state: {};
38
38
  await: {};
39
+ defer: {};
39
40
  getDefaultData: {
40
41
  type: FunctionConstructor;
41
42
  default: (data?: {}) => {};
@@ -59,6 +60,11 @@ declare const _default: {
59
60
  setup(props: Record<string, any>, context: SetupContext): ($vue: ComponentPublicInstance & any) => any;
60
61
  };
61
62
 
63
+ type StateUpdate = {
64
+ callback: Function;
65
+ beforeStateUpdate?: Function;
66
+ options?: WatchOptions;
67
+ };
62
68
  type Accessible = {
63
69
  parent: {
64
70
  self: Record<string | symbol, any>;
@@ -72,6 +78,7 @@ type PropOptions = {
72
78
  include: Record<string, any>;
73
79
  };
74
80
  type PropExclusions = Array<string> | string;
81
+
75
82
  declare function safeRequest(request: {
76
83
  try: () => Promise<any> | any;
77
84
  catch?: ((error: any) => Promise<any> | any) | false;
@@ -106,4 +113,4 @@ declare function getSubscription(): {
106
113
  subscription: Subscription;
107
114
  };
108
115
 
109
- export { access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
116
+ export { type StateUpdate, access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
1
+ import { SetupContext, ComponentPublicInstance, WatchOptions, UnwrapRef } from 'vue';
2
2
 
3
3
  type SubscriptionItem = {
4
4
  name: string;
@@ -36,6 +36,7 @@ declare const _default: {
36
36
  model: {};
37
37
  state: {};
38
38
  await: {};
39
+ defer: {};
39
40
  getDefaultData: {
40
41
  type: FunctionConstructor;
41
42
  default: (data?: {}) => {};
@@ -59,6 +60,11 @@ declare const _default: {
59
60
  setup(props: Record<string, any>, context: SetupContext): ($vue: ComponentPublicInstance & any) => any;
60
61
  };
61
62
 
63
+ type StateUpdate = {
64
+ callback: Function;
65
+ beforeStateUpdate?: Function;
66
+ options?: WatchOptions;
67
+ };
62
68
  type Accessible = {
63
69
  parent: {
64
70
  self: Record<string | symbol, any>;
@@ -72,6 +78,7 @@ type PropOptions = {
72
78
  include: Record<string, any>;
73
79
  };
74
80
  type PropExclusions = Array<string> | string;
81
+
75
82
  declare function safeRequest(request: {
76
83
  try: () => Promise<any> | any;
77
84
  catch?: ((error: any) => Promise<any> | any) | false;
@@ -106,4 +113,4 @@ declare function getSubscription(): {
106
113
  subscription: Subscription;
107
114
  };
108
115
 
109
- export { access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
116
+ export { type StateUpdate, access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
package/dist/index.js CHANGED
@@ -158,13 +158,13 @@ var Subscriptions = _Subscriptions;
158
158
  // src/ReactiveView.ts
159
159
  var import_object_manager = __toESM(require("@razaman2/object-manager"));
160
160
  var import_data_manager = __toESM(require("@razaman2/data-manager"));
161
+ var import_vue = require("vue");
161
162
 
162
163
  // package.json
163
164
  var name = "@razaman2/reactive-view";
164
- var version = "0.0.8";
165
+ var version = "0.0.10";
165
166
 
166
167
  // src/ReactiveView.ts
167
- var import_vue = require("vue");
168
168
  var props = {
169
169
  notifications: Object,
170
170
  subscriptions: Object,
@@ -172,6 +172,7 @@ var props = {
172
172
  model: {},
173
173
  state: {},
174
174
  await: {},
175
+ defer: {},
175
176
  getDefaultData: {
176
177
  type: Function,
177
178
  default: (data = {}) => data
@@ -201,7 +202,7 @@ var setup = {
201
202
  var ReactiveView_default = {
202
203
  props: __spreadValues(__spreadValues({}, setup), props),
203
204
  setup(props2, context) {
204
- var _a, _b, _c, _d, _e, _g;
205
+ var _a, _b, _c, _d, _f;
205
206
  const template = (vue, options2) => {
206
207
  var _a2, _b2, _c2;
207
208
  const vnode = context.slots.default ? (0, import_vue.h)(
@@ -217,6 +218,7 @@ var ReactiveView_default = {
217
218
  return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { $vue: vue, vnode })) != null ? _c2 : vnode;
218
219
  };
219
220
  const isValid = (0, import_vue.ref)(false);
221
+ const isRendered = (0, import_vue.ref)(false);
220
222
  const defaultData = props2.getDefaultData(
221
223
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
222
224
  );
@@ -233,41 +235,48 @@ var ReactiveView_default = {
233
235
  const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new import_data_manager.default(config);
234
236
  const sync = (0, import_vue.ref)(false);
235
237
  const options = {
236
- parent: { self: (_d = (0, import_vue.getCurrentInstance)()) == null ? void 0 : _d.proxy },
238
+ parent: { self: (0, import_vue.getCurrentInstance)().proxy },
237
239
  self: { template, isValid, getState }
238
240
  };
239
- const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = {}, self = {} } = _f, rest = __objRest(_f, ["parent", "self"]);
241
+ const _e = (_d = props2.setup(options)) != null ? _d : options, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
240
242
  if (props2.await instanceof Promise) {
241
243
  (0, import_vue.nextTick)(async () => {
242
244
  getState.replaceData(await props2.await);
243
245
  });
244
246
  }
247
+ if (props2.defer instanceof Promise) {
248
+ (0, import_vue.nextTick)(async () => {
249
+ var _a2;
250
+ isRendered.value = (_a2 = await props2.defer) != null ? _a2 : true;
251
+ });
252
+ }
245
253
  if (context.attrs["onUpdate:modelState"]) {
246
254
  const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
247
- (0, import_vue.watch)(() => import_object_manager.default.on(state).clone(), (after, before) => {
248
- var _a2;
249
- const transform = (_a2 = config2.transform) != null ? _a2 : access({ parent, self }).$transform;
250
- const diff = {
251
- before: (before == null ? void 0 : before.hasOwnProperty("")) ? before[""] : before,
252
- after: (after == null ? void 0 : after.hasOwnProperty("")) ? after[""] : after
253
- };
254
- if (sync.value) {
255
- sync.value = false;
256
- } else {
257
- config2.callback(transform ? transform(diff) : diff, getState);
258
- }
259
- }, config2.options);
255
+ (0, import_vue.onMounted)(() => {
256
+ (0, import_vue.watch)(() => import_object_manager.default.on(state).clone(), (after, before) => {
257
+ var _a2;
258
+ const beforeStateUpdate = (_a2 = config2.beforeStateUpdate) != null ? _a2 : access({ parent, self }).beforeStateUpdate;
259
+ const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
260
+ if (sync.value) {
261
+ sync.value = false;
262
+ } else {
263
+ config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
264
+ }
265
+ }, config2.options);
266
+ });
260
267
  }
261
268
  if (context.attrs["onUpdate:propsState"] || props2.sync) {
262
- const config2 = (_g = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _g : {};
263
- (0, import_vue.watch)(() => props2.state, (after, before) => {
264
- if (props2.sync && typeof config2.callback !== "function") {
265
- getState.replaceData(after);
266
- } else if (typeof config2.callback === "function") {
267
- config2.callback({ before, after }, getState);
268
- }
269
- sync.value = true;
270
- }, config2.options);
269
+ const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
270
+ (0, import_vue.onMounted)(() => {
271
+ (0, import_vue.watch)(() => props2.state, (after, before) => {
272
+ if (props2.sync && typeof config2.callback !== "function") {
273
+ getState.replaceData(after);
274
+ } else if (typeof config2.callback === "function") {
275
+ config2.callback({ before, after }, getState);
276
+ }
277
+ sync.value = true;
278
+ }, config2.options);
279
+ });
271
280
  }
272
281
  return ($vue) => {
273
282
  const setup2 = { $vue, options: parent };
@@ -281,7 +290,9 @@ var ReactiveView_default = {
281
290
  setup2.options = setup2.options.parent;
282
291
  setup2.$vue = setup2.$vue.$parent;
283
292
  }
284
- return access($vue).template($vue, { parent, self });
293
+ if (isRendered.value) {
294
+ return access($vue).template($vue, { parent, self });
295
+ }
285
296
  };
286
297
  }
287
298
  };
package/dist/index.mjs CHANGED
@@ -121,13 +121,13 @@ var Subscriptions = _Subscriptions;
121
121
  // src/ReactiveView.ts
122
122
  import ObjectManager from "@razaman2/object-manager";
123
123
  import DataManager from "@razaman2/data-manager";
124
+ import { h, ref, reactive, watch, nextTick, getCurrentInstance, onMounted } from "vue";
124
125
 
125
126
  // package.json
126
127
  var name = "@razaman2/reactive-view";
127
- var version = "0.0.8";
128
+ var version = "0.0.10";
128
129
 
129
130
  // src/ReactiveView.ts
130
- import { h, ref, reactive, watch, nextTick, getCurrentInstance } from "vue";
131
131
  var props = {
132
132
  notifications: Object,
133
133
  subscriptions: Object,
@@ -135,6 +135,7 @@ var props = {
135
135
  model: {},
136
136
  state: {},
137
137
  await: {},
138
+ defer: {},
138
139
  getDefaultData: {
139
140
  type: Function,
140
141
  default: (data = {}) => data
@@ -164,7 +165,7 @@ var setup = {
164
165
  var ReactiveView_default = {
165
166
  props: __spreadValues(__spreadValues({}, setup), props),
166
167
  setup(props2, context) {
167
- var _a, _b, _c, _d, _e, _g;
168
+ var _a, _b, _c, _d, _f;
168
169
  const template = (vue, options2) => {
169
170
  var _a2, _b2, _c2;
170
171
  const vnode = context.slots.default ? h(
@@ -180,6 +181,7 @@ var ReactiveView_default = {
180
181
  return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { $vue: vue, vnode })) != null ? _c2 : vnode;
181
182
  };
182
183
  const isValid = ref(false);
184
+ const isRendered = ref(false);
183
185
  const defaultData = props2.getDefaultData(
184
186
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
185
187
  );
@@ -196,41 +198,48 @@ var ReactiveView_default = {
196
198
  const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new DataManager(config);
197
199
  const sync = ref(false);
198
200
  const options = {
199
- parent: { self: (_d = getCurrentInstance()) == null ? void 0 : _d.proxy },
201
+ parent: { self: getCurrentInstance().proxy },
200
202
  self: { template, isValid, getState }
201
203
  };
202
- const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = {}, self = {} } = _f, rest = __objRest(_f, ["parent", "self"]);
204
+ const _e = (_d = props2.setup(options)) != null ? _d : options, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
203
205
  if (props2.await instanceof Promise) {
204
206
  nextTick(async () => {
205
207
  getState.replaceData(await props2.await);
206
208
  });
207
209
  }
210
+ if (props2.defer instanceof Promise) {
211
+ nextTick(async () => {
212
+ var _a2;
213
+ isRendered.value = (_a2 = await props2.defer) != null ? _a2 : true;
214
+ });
215
+ }
208
216
  if (context.attrs["onUpdate:modelState"]) {
209
217
  const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
210
- watch(() => ObjectManager.on(state).clone(), (after, before) => {
211
- var _a2;
212
- const transform = (_a2 = config2.transform) != null ? _a2 : access({ parent, self }).$transform;
213
- const diff = {
214
- before: (before == null ? void 0 : before.hasOwnProperty("")) ? before[""] : before,
215
- after: (after == null ? void 0 : after.hasOwnProperty("")) ? after[""] : after
216
- };
217
- if (sync.value) {
218
- sync.value = false;
219
- } else {
220
- config2.callback(transform ? transform(diff) : diff, getState);
221
- }
222
- }, config2.options);
218
+ onMounted(() => {
219
+ watch(() => ObjectManager.on(state).clone(), (after, before) => {
220
+ var _a2;
221
+ const beforeStateUpdate = (_a2 = config2.beforeStateUpdate) != null ? _a2 : access({ parent, self }).beforeStateUpdate;
222
+ const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
223
+ if (sync.value) {
224
+ sync.value = false;
225
+ } else {
226
+ config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
227
+ }
228
+ }, config2.options);
229
+ });
223
230
  }
224
231
  if (context.attrs["onUpdate:propsState"] || props2.sync) {
225
- const config2 = (_g = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _g : {};
226
- watch(() => props2.state, (after, before) => {
227
- if (props2.sync && typeof config2.callback !== "function") {
228
- getState.replaceData(after);
229
- } else if (typeof config2.callback === "function") {
230
- config2.callback({ before, after }, getState);
231
- }
232
- sync.value = true;
233
- }, config2.options);
232
+ const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
233
+ onMounted(() => {
234
+ watch(() => props2.state, (after, before) => {
235
+ if (props2.sync && typeof config2.callback !== "function") {
236
+ getState.replaceData(after);
237
+ } else if (typeof config2.callback === "function") {
238
+ config2.callback({ before, after }, getState);
239
+ }
240
+ sync.value = true;
241
+ }, config2.options);
242
+ });
234
243
  }
235
244
  return ($vue) => {
236
245
  const setup2 = { $vue, options: parent };
@@ -244,7 +253,9 @@ var ReactiveView_default = {
244
253
  setup2.options = setup2.options.parent;
245
254
  setup2.$vue = setup2.$vue.$parent;
246
255
  }
247
- return access($vue).template($vue, { parent, self });
256
+ if (isRendered.value) {
257
+ return access($vue).template($vue, { parent, self });
258
+ }
248
259
  };
249
260
  }
250
261
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -8,7 +8,8 @@
8
8
  "scripts": {
9
9
  "prepublishOnly": "npm run build",
10
10
  "build": "tsup src/index.ts --format cjs,esm --dts",
11
- "lint": "tsc"
11
+ "lint": "tsc",
12
+ "test": "cd tests/vue-ts && npm run dev"
12
13
  },
13
14
  "keywords": [
14
15
  "vue",
@@ -19,28 +20,24 @@
19
20
  "author": "razaman2",
20
21
  "license": "MIT",
21
22
  "dependencies": {
22
- "@razaman2/collection-proxy": "^0.0.11",
23
- "@razaman2/data-manager": "^3.2.8",
23
+ "@razaman2/collection-proxy": "^0.0.29",
24
+ "@razaman2/data-manager": "^3.2.9",
24
25
  "@razaman2/object-manager": "^3.3.9",
25
26
  "date-fns": "^3.6.0",
26
27
  "date-fns-tz": "^3.1.3",
27
- "uuid": "^9.0.1",
28
- "vue": "^3.4.27"
28
+ "uuid": "^10.0.0",
29
+ "vue": "^3.5.3"
29
30
  },
30
31
  "devDependencies": {
31
- "@types/uuid": "^9.0.8",
32
- "tsup": "^8.0.2",
33
- "typescript": "^5.4.5",
34
- "vitest": "^1.6.0"
32
+ "@types/uuid": "^10.0.0",
33
+ "tsup": "^8.2.4",
34
+ "typescript": "^5.5.4",
35
+ "vitest": "^2.0.5"
35
36
  },
36
37
  "publishConfig": {
37
38
  "access": "public"
38
39
  },
39
40
  "files": [
40
41
  "dist"
41
- ],
42
- "repository": {
43
- "type": "git",
44
- "url": "https://github.com/razaman2/reactive-view.git"
45
- }
42
+ ]
46
43
  }