saasufy-components 7.0.3 → 7.2.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.
package/README.md CHANGED
@@ -321,7 +321,8 @@ In addition to the slots shown above, the `collection-viewer` also supports the
321
321
  - `collection-page-size`: Sets how many items from the collection are displayed at once. This is useful for pagination, allowing users to navigate through large sets of data in chunks.
322
322
  - `collection-page-offset`: Indicates the current page offset in the collection's data. It’s like telling the viewer which page of data you want to display initially.
323
323
  - `collection-get-count`: If this attribute is present, the component will get the record count of the target view. The count can be rendered into the template by prefixing the model name with a dollar sign and accessing the `count` property like this: `{{$MyModelName.count}}`.
324
- - `collection-view-primary-fields`: An optional list of field names to specify which specific `collection-view-params` to watch for real time updates. Fewer primary fields means that the view will be exposed to a broader range of real time updates but at the cost of performance. It is generally recommended to have just one primary field.
324
+ - `collection-view-primary-fields`: An optional list of field names to specify which specific `collection-view-params` to watch for realtime updates. Fewer primary fields means that the view will be exposed to a broader range of realtime updates but at the cost of performance. It is generally recommended to have just one primary field.
325
+ - `collection-disable-realtime`: If this attribute is present, the underlying collection will not listen for changes nor update in realtime. Fields of records that are in view may still update in realtime.
325
326
  - `auto-reset-page-offset`: If this attribute is present, the `collection-page-offset` will be reset to zero whenever the view params change.
326
327
  - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `collection-viewer` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `SubChat`, then `{{Chat.message}}` would become `{{SubChat.message}}`.
327
328
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
@@ -532,7 +533,7 @@ In the example above, the name of the first element can be accessed with `{{Cate
532
533
 
533
534
  ### model-input
534
535
 
535
- Used for displaying and editing a single field of a model instance in real time.
536
+ Used for displaying and editing a single field of a model instance in realtime.
536
537
 
537
538
  **Import**
538
539
 
@@ -583,7 +584,7 @@ Used for displaying and editing a single field of a model instance in real time.
583
584
 
584
585
  ### model-text
585
586
 
586
- Used to displaying a field of a model instance in real time.
587
+ Used to displaying a field of a model instance in realtime.
587
588
 
588
589
  **Import**
589
590
 
@@ -18,10 +18,10 @@ class CollectionViewer extends SocketConsumer {
18
18
  modal.show(event.detail.message, event.detail.callback);
19
19
  };
20
20
 
21
- this.handleCRUDCreateEvent = (event) => {
21
+ this.handleCRUDCreateEvent = async (event) => {
22
22
  event.stopPropagation();
23
23
  if (this.collection) {
24
- this.collection.create(event.detail);
24
+ await this.collection.create(event.detail);
25
25
  this.dispatchEvent(
26
26
  new CustomEvent('collectionCreate', {
27
27
  detail: {
@@ -31,13 +31,16 @@ class CollectionViewer extends SocketConsumer {
31
31
  bubbles: true
32
32
  })
33
33
  );
34
+ if (this.hasAttribute('collection-disable-realtime') && this.collection) {
35
+ this.collection.reloadCurrentPage();
36
+ }
34
37
  }
35
38
  };
36
39
 
37
- this.handleCRUDDeleteEvent = (event) => {
40
+ this.handleCRUDDeleteEvent = async (event) => {
38
41
  event.stopPropagation();
39
42
  if (this.collection) {
40
- this.collection.delete(event.detail);
43
+ await this.collection.delete(event.detail);
41
44
  this.dispatchEvent(
42
45
  new CustomEvent('collectionDelete', {
43
46
  detail: {
@@ -47,6 +50,9 @@ class CollectionViewer extends SocketConsumer {
47
50
  bubbles: true
48
51
  })
49
52
  );
53
+ if (this.hasAttribute('collection-disable-realtime') && this.collection) {
54
+ this.collection.reloadCurrentPage();
55
+ }
50
56
  }
51
57
  };
52
58
 
@@ -123,6 +129,7 @@ class CollectionViewer extends SocketConsumer {
123
129
  'collection-page-size',
124
130
  'collection-page-offset',
125
131
  'collection-get-count',
132
+ 'collection-disable-realtime',
126
133
  'auto-reset-page-offset',
127
134
  'max-show-loader',
128
135
  'type-alias',
@@ -289,6 +296,7 @@ class CollectionViewer extends SocketConsumer {
289
296
  let collectionPageSize = this.getAttribute('collection-page-size');
290
297
  let collectionPageOffset = this.getAttribute('collection-page-offset');
291
298
  let collectionGetCount = this.hasAttribute('collection-get-count');
299
+ let collectionDisableRealtime = this.hasAttribute('collection-disable-realtime');
292
300
  let hideErrorLogs = this.hasAttribute('hide-error-logs');
293
301
  let collectionReloadDelay = Number(
294
302
  this.getAttribute('collection-reload-delay') || DEFAULT_RELOAD_DELAY
@@ -312,7 +320,8 @@ class CollectionViewer extends SocketConsumer {
312
320
  pageSize: Number(collectionPageSize || 10),
313
321
  pageOffset: Number(collectionPageOffset || 0),
314
322
  changeReloadDelay: collectionReloadDelay,
315
- getCount: collectionGetCount
323
+ getCount: collectionGetCount,
324
+ realtimeCollection: !collectionDisableRealtime
316
325
  });
317
326
 
318
327
  this.shadowRoot.innerHTML = `
@@ -352,8 +361,6 @@ class CollectionViewer extends SocketConsumer {
352
361
 
353
362
  (async () => {
354
363
  for await (let event of this.collection.listener('change')) {
355
- // Ignore change events which originate from this collection instance.
356
- if (!event.isRemote) continue;
357
364
  this.renderList();
358
365
  this.updatePageButtons();
359
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.0.3",
3
+ "version": "7.2.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -63,32 +63,17 @@ export function createReactiveCollection(collectionOptions, callback) {
63
63
  collection.safeValue = [];
64
64
 
65
65
  (async () => {
66
- let changes = {};
67
66
  for await (let event of collection.listener('change')) {
68
- // Ignore change events which originate from this collection instance.
69
- if (!event.isRemote) continue;
70
-
71
- if (event.resourceId != null && changes[event.resourceId] !== false) {
72
- changes[event.resourceId] = event.isRemote;
73
- }
74
-
75
67
  if (!collection.isLoaded) continue;
76
-
77
68
  collection.safeValue = collection.value.map(toSafeModelValue);
78
-
79
- callback({
80
- changes
81
- });
82
- changes = {};
69
+ callback();
83
70
  }
84
71
  })();
85
72
 
86
73
  (async () => {
87
74
  for await (let event of collection.listener('load')) {
88
75
  if (collection.isLoaded && !collection.value.length) {
89
- callback({
90
- changes: {}
91
- });
76
+ callback();
92
77
  }
93
78
  }
94
79
  })();
@@ -114,17 +99,9 @@ export function createReactiveModel(modelOptions, callback) {
114
99
  })();
115
100
 
116
101
  (async () => {
117
- let changes = {};
118
102
  for await (let event of model.listener('change')) {
119
- if (changes[event.resourceField] !== false) {
120
- changes[event.resourceField] = event.isRemote;
121
- }
122
-
123
103
  model.safeValue = toSafeModelValue(model.value);
124
- callback({
125
- changes
126
- });
127
- changes = {};
104
+ callback();
128
105
  }
129
106
  })();
130
107