@suey/rxp-meta 0.2.4 → 0.3.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.
|
@@ -39,13 +39,11 @@ class MetadataManager {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
defineMetadataInVector(metadataKey, metadata) {
|
|
42
|
-
let hasThisMetadata = false;
|
|
43
42
|
if (this.hasMetadata(metadataKey)) {
|
|
44
43
|
const vector = this.metadataMap.get(metadataKey);
|
|
45
44
|
if (!Array.isArray(vector))
|
|
46
45
|
throw new Error(`defineMetadataInVector: current metadata value is not an array`);
|
|
47
|
-
|
|
48
|
-
this.metadataMap.set(metadataKey, newVector);
|
|
46
|
+
this.metadataMap.set(metadataKey, [...vector, metadata]);
|
|
49
47
|
this.rxpInnerStore.update();
|
|
50
48
|
}
|
|
51
49
|
else {
|
|
@@ -57,7 +55,7 @@ class MetadataManager {
|
|
|
57
55
|
delMetadataInVector(metadataKey, metadata) {
|
|
58
56
|
if (!this.hasMetadata(metadataKey))
|
|
59
57
|
return;
|
|
60
|
-
let
|
|
58
|
+
let metadataIsDeleted = false;
|
|
61
59
|
const vector = this.metadataMap.get(metadataKey) ?? [];
|
|
62
60
|
if (!Array.isArray(vector))
|
|
63
61
|
throw new Error(`delMetadataInVector: current metadata value is not an array`);
|
|
@@ -66,20 +64,24 @@ class MetadataManager {
|
|
|
66
64
|
this.rxpInnerStore.update();
|
|
67
65
|
return;
|
|
68
66
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const newVector = vector.filter(v => {
|
|
68
|
+
if (metadataIsDeleted)
|
|
69
|
+
return true;
|
|
70
|
+
if (v === metadata) {
|
|
71
|
+
metadataIsDeleted = true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
74
75
|
});
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
76
|
+
if (metadataIsDeleted) {
|
|
77
|
+
if (newVector.length === 0) {
|
|
77
78
|
this.metadataMap.delete(metadataKey);
|
|
78
79
|
this.rxpInnerStore.update();
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
|
-
this.metadataMap.set(metadataKey,
|
|
82
|
+
this.metadataMap.set(metadataKey, newVector);
|
|
82
83
|
this.rxpInnerStore.update();
|
|
84
|
+
return;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
useMetadata(metadataKey) {
|
|
@@ -133,7 +135,7 @@ class MetadataManager {
|
|
|
133
135
|
const vec = this.metadataMap.get(metadataKey);
|
|
134
136
|
if (!Array.isArray(vec))
|
|
135
137
|
return false;
|
|
136
|
-
return vec.
|
|
138
|
+
return vec.includes(metadata);
|
|
137
139
|
}
|
|
138
140
|
useFollowMetadata(metadataKey, metadata) {
|
|
139
141
|
(0, react_1.useEffect)(() => {
|
|
@@ -36,13 +36,11 @@ export class MetadataManager {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
defineMetadataInVector(metadataKey, metadata) {
|
|
39
|
-
let hasThisMetadata = false;
|
|
40
39
|
if (this.hasMetadata(metadataKey)) {
|
|
41
40
|
const vector = this.metadataMap.get(metadataKey);
|
|
42
41
|
if (!Array.isArray(vector))
|
|
43
42
|
throw new Error(`defineMetadataInVector: current metadata value is not an array`);
|
|
44
|
-
|
|
45
|
-
this.metadataMap.set(metadataKey, newVector);
|
|
43
|
+
this.metadataMap.set(metadataKey, [...vector, metadata]);
|
|
46
44
|
this.rxpInnerStore.update();
|
|
47
45
|
}
|
|
48
46
|
else {
|
|
@@ -54,7 +52,7 @@ export class MetadataManager {
|
|
|
54
52
|
delMetadataInVector(metadataKey, metadata) {
|
|
55
53
|
if (!this.hasMetadata(metadataKey))
|
|
56
54
|
return;
|
|
57
|
-
let
|
|
55
|
+
let metadataIsDeleted = false;
|
|
58
56
|
const vector = this.metadataMap.get(metadataKey) ?? [];
|
|
59
57
|
if (!Array.isArray(vector))
|
|
60
58
|
throw new Error(`delMetadataInVector: current metadata value is not an array`);
|
|
@@ -63,20 +61,24 @@ export class MetadataManager {
|
|
|
63
61
|
this.rxpInnerStore.update();
|
|
64
62
|
return;
|
|
65
63
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
const newVector = vector.filter(v => {
|
|
65
|
+
if (metadataIsDeleted)
|
|
66
|
+
return true;
|
|
67
|
+
if (v === metadata) {
|
|
68
|
+
metadataIsDeleted = true;
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
71
72
|
});
|
|
72
|
-
if (
|
|
73
|
-
if (
|
|
73
|
+
if (metadataIsDeleted) {
|
|
74
|
+
if (newVector.length === 0) {
|
|
74
75
|
this.metadataMap.delete(metadataKey);
|
|
75
76
|
this.rxpInnerStore.update();
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
|
-
this.metadataMap.set(metadataKey,
|
|
79
|
+
this.metadataMap.set(metadataKey, newVector);
|
|
79
80
|
this.rxpInnerStore.update();
|
|
81
|
+
return;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
useMetadata(metadataKey) {
|
|
@@ -130,7 +132,7 @@ export class MetadataManager {
|
|
|
130
132
|
const vec = this.metadataMap.get(metadataKey);
|
|
131
133
|
if (!Array.isArray(vec))
|
|
132
134
|
return false;
|
|
133
|
-
return vec.
|
|
135
|
+
return vec.includes(metadata);
|
|
134
136
|
}
|
|
135
137
|
useFollowMetadata(metadataKey, metadata) {
|
|
136
138
|
useEffect(() => {
|