shogun-button-react 1.3.9 → 1.3.11
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShogunCore } from "shogun-core";
|
|
1
|
+
import { ShogunCore, BasePlugin } from "shogun-core";
|
|
2
2
|
export interface GunAdvancedPluginConfig {
|
|
3
3
|
enableDebug?: boolean;
|
|
4
4
|
enableConnectionMonitoring?: boolean;
|
|
@@ -38,13 +38,15 @@ export interface GunStateResult<T> {
|
|
|
38
38
|
remove: () => Promise<void>;
|
|
39
39
|
refresh: () => void;
|
|
40
40
|
}
|
|
41
|
-
export declare class GunAdvancedPlugin {
|
|
42
|
-
|
|
41
|
+
export declare class GunAdvancedPlugin extends BasePlugin {
|
|
42
|
+
version: string;
|
|
43
|
+
readonly name = "gun-advanced";
|
|
44
|
+
core: ShogunCore;
|
|
43
45
|
private config;
|
|
44
46
|
private debugEnabled;
|
|
45
47
|
private connectionMonitors;
|
|
46
48
|
private collectionCache;
|
|
47
|
-
constructor(
|
|
49
|
+
constructor(core: ShogunCore, config?: GunAdvancedPluginConfig);
|
|
48
50
|
setDebugEnabled(enabled: boolean): void;
|
|
49
51
|
private log;
|
|
50
52
|
createHooks(): {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { BasePlugin } from "shogun-core";
|
|
3
|
+
export class GunAdvancedPlugin extends BasePlugin {
|
|
4
|
+
constructor(core, config = {}) {
|
|
5
|
+
super();
|
|
6
|
+
this.name = "gun-advanced";
|
|
4
7
|
this.connectionMonitors = new Map();
|
|
5
8
|
this.collectionCache = new Map();
|
|
6
|
-
this.
|
|
9
|
+
this.core = core;
|
|
7
10
|
this.config = {
|
|
8
11
|
enableDebug: true,
|
|
9
12
|
enableConnectionMonitoring: true,
|
|
@@ -39,11 +42,11 @@ export class GunAdvancedPlugin {
|
|
|
39
42
|
const isMounted = React.useRef(true);
|
|
40
43
|
React.useEffect(() => {
|
|
41
44
|
var _a;
|
|
42
|
-
if (!((_a = this.
|
|
45
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
43
46
|
return;
|
|
44
47
|
setIsLoading(true);
|
|
45
48
|
setError(null);
|
|
46
|
-
const gunRef = this.
|
|
49
|
+
const gunRef = this.core.gun.get(path);
|
|
47
50
|
const off = gunRef.on((item) => {
|
|
48
51
|
if (!isMounted.current)
|
|
49
52
|
return;
|
|
@@ -69,14 +72,14 @@ export class GunAdvancedPlugin {
|
|
|
69
72
|
}, [path]);
|
|
70
73
|
const update = async (updates) => {
|
|
71
74
|
var _a;
|
|
72
|
-
if (!((_a = this.
|
|
75
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
73
76
|
throw new Error('SDK not initialized or user not logged in');
|
|
74
77
|
}
|
|
75
78
|
try {
|
|
76
79
|
setError(null);
|
|
77
80
|
const newData = { ...data, ...updates };
|
|
78
81
|
await new Promise((resolve, reject) => {
|
|
79
|
-
this.
|
|
82
|
+
this.core.gun.get(path).put(newData, (ack) => {
|
|
80
83
|
if (ack.err) {
|
|
81
84
|
reject(new Error(ack.err));
|
|
82
85
|
}
|
|
@@ -96,13 +99,13 @@ export class GunAdvancedPlugin {
|
|
|
96
99
|
};
|
|
97
100
|
const set = async (newData) => {
|
|
98
101
|
var _a;
|
|
99
|
-
if (!((_a = this.
|
|
102
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
100
103
|
throw new Error('SDK not initialized or user not logged in');
|
|
101
104
|
}
|
|
102
105
|
try {
|
|
103
106
|
setError(null);
|
|
104
107
|
await new Promise((resolve, reject) => {
|
|
105
|
-
this.
|
|
108
|
+
this.core.gun.get(path).put(newData, (ack) => {
|
|
106
109
|
if (ack.err) {
|
|
107
110
|
reject(new Error(ack.err));
|
|
108
111
|
}
|
|
@@ -122,13 +125,13 @@ export class GunAdvancedPlugin {
|
|
|
122
125
|
};
|
|
123
126
|
const remove = async () => {
|
|
124
127
|
var _a;
|
|
125
|
-
if (!((_a = this.
|
|
128
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
126
129
|
throw new Error('SDK not initialized or user not logged in');
|
|
127
130
|
}
|
|
128
131
|
try {
|
|
129
132
|
setError(null);
|
|
130
133
|
await new Promise((resolve, reject) => {
|
|
131
|
-
this.
|
|
134
|
+
this.core.gun.get(path).put(null, (ack) => {
|
|
132
135
|
if (ack.err) {
|
|
133
136
|
reject(new Error(ack.err));
|
|
134
137
|
}
|
|
@@ -151,8 +154,8 @@ export class GunAdvancedPlugin {
|
|
|
151
154
|
var _a;
|
|
152
155
|
setIsLoading(true);
|
|
153
156
|
setError(null);
|
|
154
|
-
if ((_a = this.
|
|
155
|
-
this.
|
|
157
|
+
if ((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) {
|
|
158
|
+
this.core.gun.get(path).once(() => { });
|
|
156
159
|
}
|
|
157
160
|
};
|
|
158
161
|
return {
|
|
@@ -176,11 +179,11 @@ export class GunAdvancedPlugin {
|
|
|
176
179
|
const cacheKey = `${path}-${JSON.stringify(options)}`;
|
|
177
180
|
React.useEffect(() => {
|
|
178
181
|
var _a;
|
|
179
|
-
if (!((_a = this.
|
|
182
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
180
183
|
return;
|
|
181
184
|
setIsLoading(true);
|
|
182
185
|
setError(null);
|
|
183
|
-
const gunRef = this.
|
|
186
|
+
const gunRef = this.core.gun.get(path);
|
|
184
187
|
const tempItems = [];
|
|
185
188
|
const processItems = (items) => {
|
|
186
189
|
if (!isMounted.current)
|
|
@@ -255,19 +258,19 @@ export class GunAdvancedPlugin {
|
|
|
255
258
|
setIsLoading(true);
|
|
256
259
|
setError(null);
|
|
257
260
|
this.collectionCache.delete(cacheKey);
|
|
258
|
-
if ((_a = this.
|
|
259
|
-
this.
|
|
261
|
+
if ((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) {
|
|
262
|
+
this.core.gun.get(path).once(() => { });
|
|
260
263
|
}
|
|
261
264
|
};
|
|
262
265
|
const addItem = async (item) => {
|
|
263
266
|
var _a;
|
|
264
|
-
if (!((_a = this.
|
|
267
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
265
268
|
throw new Error('SDK not initialized or user not logged in');
|
|
266
269
|
}
|
|
267
270
|
try {
|
|
268
271
|
setError(null);
|
|
269
272
|
await new Promise((resolve, reject) => {
|
|
270
|
-
this.
|
|
273
|
+
this.core.gun.get(path).set(item, (ack) => {
|
|
271
274
|
if (ack.err) {
|
|
272
275
|
reject(new Error(ack.err));
|
|
273
276
|
}
|
|
@@ -288,13 +291,13 @@ export class GunAdvancedPlugin {
|
|
|
288
291
|
};
|
|
289
292
|
const updateItem = async (id, updates) => {
|
|
290
293
|
var _a;
|
|
291
|
-
if (!((_a = this.
|
|
294
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
292
295
|
throw new Error('SDK not initialized or user not logged in');
|
|
293
296
|
}
|
|
294
297
|
try {
|
|
295
298
|
setError(null);
|
|
296
299
|
await new Promise((resolve, reject) => {
|
|
297
|
-
this.
|
|
300
|
+
this.core.gun.get(path).get(id).put(updates, (ack) => {
|
|
298
301
|
if (ack.err) {
|
|
299
302
|
reject(new Error(ack.err));
|
|
300
303
|
}
|
|
@@ -315,13 +318,13 @@ export class GunAdvancedPlugin {
|
|
|
315
318
|
};
|
|
316
319
|
const removeItem = async (id) => {
|
|
317
320
|
var _a;
|
|
318
|
-
if (!((_a = this.
|
|
321
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
319
322
|
throw new Error('SDK not initialized or user not logged in');
|
|
320
323
|
}
|
|
321
324
|
try {
|
|
322
325
|
setError(null);
|
|
323
326
|
await new Promise((resolve, reject) => {
|
|
324
|
-
this.
|
|
327
|
+
this.core.gun.get(path).get(id).put(null, (ack) => {
|
|
325
328
|
if (ack.err) {
|
|
326
329
|
reject(new Error(ack.err));
|
|
327
330
|
}
|
|
@@ -363,10 +366,10 @@ export class GunAdvancedPlugin {
|
|
|
363
366
|
const [error, setError] = React.useState(null);
|
|
364
367
|
React.useEffect(() => {
|
|
365
368
|
var _a;
|
|
366
|
-
if (!this.config.enableConnectionMonitoring || !((_a = this.
|
|
369
|
+
if (!this.config.enableConnectionMonitoring || !((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
367
370
|
return;
|
|
368
371
|
let timeoutId;
|
|
369
|
-
const gunRef = this.
|
|
372
|
+
const gunRef = this.core.gun.get(path);
|
|
370
373
|
const resetTimeout = () => {
|
|
371
374
|
clearTimeout(timeoutId);
|
|
372
375
|
timeoutId = window.setTimeout(() => {
|
|
@@ -396,10 +399,10 @@ export class GunAdvancedPlugin {
|
|
|
396
399
|
useGunDebug(path, enabled = true) {
|
|
397
400
|
React.useEffect(() => {
|
|
398
401
|
var _a;
|
|
399
|
-
if (!enabled || !this.debugEnabled || !((_a = this.
|
|
402
|
+
if (!enabled || !this.debugEnabled || !((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
400
403
|
return;
|
|
401
404
|
this.log(`Debug mode enabled for ${path}`);
|
|
402
|
-
const gunRef = this.
|
|
405
|
+
const gunRef = this.core.gun.get(path);
|
|
403
406
|
const off = gunRef.on((data, key) => {
|
|
404
407
|
this.log(`[${path}] Update:`, {
|
|
405
408
|
key,
|
|
@@ -419,9 +422,9 @@ export class GunAdvancedPlugin {
|
|
|
419
422
|
const [key, setKey] = React.useState(null);
|
|
420
423
|
React.useEffect(() => {
|
|
421
424
|
var _a;
|
|
422
|
-
if (!((_a = this.
|
|
425
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
423
426
|
return;
|
|
424
|
-
const gunRef = this.
|
|
427
|
+
const gunRef = this.core.gun.get(path);
|
|
425
428
|
const off = gunRef.on((item, itemKey) => {
|
|
426
429
|
if (item) {
|
|
427
430
|
setData(item);
|
|
@@ -441,11 +444,11 @@ export class GunAdvancedPlugin {
|
|
|
441
444
|
}
|
|
442
445
|
async put(path, data) {
|
|
443
446
|
var _a;
|
|
444
|
-
if (!((_a = this.
|
|
447
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
445
448
|
throw new Error('SDK not initialized or user not logged in');
|
|
446
449
|
}
|
|
447
450
|
return new Promise((resolve, reject) => {
|
|
448
|
-
this.
|
|
451
|
+
this.core.gun.get(path).put(data, (ack) => {
|
|
449
452
|
if (ack.err) {
|
|
450
453
|
reject(new Error(ack.err));
|
|
451
454
|
}
|
|
@@ -457,17 +460,17 @@ export class GunAdvancedPlugin {
|
|
|
457
460
|
}
|
|
458
461
|
get(path) {
|
|
459
462
|
var _a;
|
|
460
|
-
if (!((_a = this.
|
|
463
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
|
|
461
464
|
return null;
|
|
462
|
-
return this.
|
|
465
|
+
return this.core.gun.get(path);
|
|
463
466
|
}
|
|
464
467
|
async remove(path) {
|
|
465
468
|
var _a;
|
|
466
|
-
if (!((_a = this.
|
|
469
|
+
if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn()) {
|
|
467
470
|
throw new Error('SDK not initialized or user not logged in');
|
|
468
471
|
}
|
|
469
472
|
return new Promise((resolve, reject) => {
|
|
470
|
-
this.
|
|
473
|
+
this.core.gun.get(path).put(null, (ack) => {
|
|
471
474
|
if (ack.err) {
|
|
472
475
|
reject(new Error(ack.err));
|
|
473
476
|
}
|