svelte-common 5.0.6 → 5.1.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/pagination.mjs +19 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "5.0.6",
3
+ "version": "5.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "svelte-command": "^1.1.43",
41
- "svelte-entitlement": "^1.2.55"
41
+ "svelte-entitlement": "^1.2.56"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@semantic-release/commit-analyzer": "^10.0.1",
@@ -5,16 +5,30 @@
5
5
  export class Pagination {
6
6
  #subscriptions = new Set();
7
7
  #data;
8
+ #unsubscribeData;
9
+
8
10
  #itemsPerPage = 1;
9
11
  #page = 1;
10
12
 
11
13
  constructor(data, itemsPerPage = 10) {
12
- this.#data = data;
14
+ this.data = data;
13
15
  this.itemsPerPage = itemsPerPage;
14
16
  }
15
17
 
16
18
  set data(data) {
17
- this.#data = data;
19
+ if (this.#unsubscribeData) {
20
+ this.#unsubscribeData();
21
+ this.#unsubscribeData = undefined;
22
+ }
23
+
24
+ if (data?.subscribe) {
25
+ this.#unsubscribeData = data.subscribe(newData => {
26
+ this.#data = newData;
27
+ });
28
+ } else {
29
+ this.#data = data;
30
+ }
31
+
18
32
  this.#subscriptions.forEach(subscription => subscription(this));
19
33
  }
20
34
 
@@ -63,7 +77,9 @@ export class Pagination {
63
77
  *items() {
64
78
  const n = this.page - 1;
65
79
 
66
- const data = Array.isArray(this.data) ? this.#data : [...this.#data.values()];
80
+ const data = Array.isArray(this.data)
81
+ ? this.#data
82
+ : [...this.#data.values()];
67
83
 
68
84
  for (const item of data.slice(
69
85
  n * this.itemsPerPage,