@rbxts/replion 1.0.18 → 1.0.19
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 +1 -1
- package/package.json +1 -1
- package/src/BaseReplion.lua +20 -8
- package/src/Client.lua +7 -4
- package/src/Server.lua +7 -4
- package/src/Shared.lua +0 -2
- package/src/index.d.ts +6 -1
package/README.md
CHANGED
package/package.json
CHANGED
package/src/BaseReplion.lua
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
--!strict
|
|
2
|
-
export type GenericDataTable = { [string]: any };
|
|
3
|
-
|
|
4
2
|
local isTypeScriptEnv = script.Parent.Name == 'src';
|
|
5
3
|
local dependencies = if isTypeScriptEnv then script.Parent.Parent.Parent else script.Parent.Parent;
|
|
6
4
|
local Shared = require(script.Parent.Shared);
|
|
7
5
|
local Signal = require(isTypeScriptEnv and dependencies['sleitnick-signal'] or dependencies.Signal);
|
|
8
6
|
|
|
7
|
+
export type GenericDataTable = { [string]: any };
|
|
8
|
+
export type Observer = (newValue: any, oldValue: any) -> ();
|
|
9
|
+
|
|
9
10
|
local BaseReplion = {};
|
|
10
11
|
BaseReplion.__index = BaseReplion;
|
|
11
12
|
|
|
@@ -25,10 +26,12 @@ function BaseReplion:get(path: { string }?)
|
|
|
25
26
|
return Shared.getNestedValue(self.data, path);
|
|
26
27
|
end;
|
|
27
28
|
|
|
28
|
-
function BaseReplion:
|
|
29
|
+
function BaseReplion:subscribe(path: { string }?, callback: Observer)
|
|
29
30
|
if not path then
|
|
30
|
-
|
|
31
|
-
return
|
|
31
|
+
local connection = self._allSignal:Connect(callback);
|
|
32
|
+
return function()
|
|
33
|
+
connection:Disconnect()
|
|
34
|
+
end;
|
|
32
35
|
end;
|
|
33
36
|
|
|
34
37
|
local signalKey = Shared.getSignalKey(path);
|
|
@@ -36,15 +39,24 @@ function BaseReplion:observe(path: { string }?, callback: (any, any) -> ())
|
|
|
36
39
|
self._signals[signalKey] = Signal.new();
|
|
37
40
|
end;
|
|
38
41
|
|
|
39
|
-
local initialValue = Shared.getNestedValue(self.data, path);
|
|
40
|
-
|
|
41
|
-
task.spawn(callback, initialValue, nil);
|
|
42
42
|
local connection = self._signals[signalKey]:Connect(callback);
|
|
43
|
+
|
|
43
44
|
return function()
|
|
44
45
|
connection:Disconnect();
|
|
45
46
|
end;
|
|
46
47
|
end;
|
|
47
48
|
|
|
49
|
+
function BaseReplion:observe(path: { string }?, callback: Observer)
|
|
50
|
+
if path then
|
|
51
|
+
local initialValue = Shared.getNestedValue(self.data, path);
|
|
52
|
+
task.spawn(callback, initialValue, nil);
|
|
53
|
+
else
|
|
54
|
+
task.spawn(callback, self.data, nil);
|
|
55
|
+
end;
|
|
56
|
+
|
|
57
|
+
return self:subscribe(path, callback);
|
|
58
|
+
end;
|
|
59
|
+
|
|
48
60
|
function BaseReplion:destroy()
|
|
49
61
|
self._allSignal:Destroy();
|
|
50
62
|
for _, signal in self._signals do
|
package/src/Client.lua
CHANGED
|
@@ -5,7 +5,6 @@ local BaseReplion = require(script.Parent.BaseReplion)
|
|
|
5
5
|
local Shared = require(script.Parent.Shared);
|
|
6
6
|
local Signal = require(isTypeScriptEnv and dependencies['sleitnick-signal'] or dependencies.Signal);
|
|
7
7
|
|
|
8
|
-
type Observer = (newValue: any, oldValue: any) -> ();
|
|
9
8
|
type Deletion = { path: { string }, oldTable: any };
|
|
10
9
|
|
|
11
10
|
local remote = script.Parent:WaitForChild(Shared.REMOTE_NAME) :: RemoteEvent;
|
|
@@ -49,7 +48,7 @@ function Client.waitForReplion(channel: string)
|
|
|
49
48
|
return replion;
|
|
50
49
|
end;
|
|
51
50
|
|
|
52
|
-
function Client.new(channel: string, data:
|
|
51
|
+
function Client.new(channel: string, data: BaseReplion.GenericDataTable)
|
|
53
52
|
local self = setmetatable({}, Client);
|
|
54
53
|
|
|
55
54
|
self.channel = channel;
|
|
@@ -63,7 +62,11 @@ function Client:get(path: { string }?)
|
|
|
63
62
|
return self._base:get(path);
|
|
64
63
|
end;
|
|
65
64
|
|
|
66
|
-
function Client:
|
|
65
|
+
function Client:subscribe(path: { string }?, callback: BaseReplion.Observer)
|
|
66
|
+
return self._base:subscribe(path, callback);
|
|
67
|
+
end;
|
|
68
|
+
|
|
69
|
+
function Client:observe(path: { string }?, callback: BaseReplion.Observer)
|
|
67
70
|
return self._base:observe(path, callback);
|
|
68
71
|
end;
|
|
69
72
|
|
|
@@ -123,7 +126,7 @@ function Client:_notifyRecursiveUpdates(currentPath: { string }, updateTree: any
|
|
|
123
126
|
end;
|
|
124
127
|
end;
|
|
125
128
|
|
|
126
|
-
function Client:_applyUpdates(updates:
|
|
129
|
+
function Client:_applyUpdates(updates: BaseReplion.GenericDataTable)
|
|
127
130
|
local deletions: { Deletion } = {};
|
|
128
131
|
self:_collectDeletions(self._base.data, updates, {}, deletions);
|
|
129
132
|
|
package/src/Server.lua
CHANGED
|
@@ -10,9 +10,8 @@ local Sift = require(isTypeScriptEnv and dependencies.sift.out or dependencies.S
|
|
|
10
10
|
type ServerConfig = {
|
|
11
11
|
channel: string;
|
|
12
12
|
replicateTo: Player?;
|
|
13
|
-
data:
|
|
13
|
+
data: BaseReplion.GenericDataTable;
|
|
14
14
|
};
|
|
15
|
-
type Observer = (newValue: any, oldValue: any) -> ();
|
|
16
15
|
|
|
17
16
|
local remote = script.Parent:FindFirstChild(Shared.REMOTE_NAME) :: RemoteEvent;
|
|
18
17
|
if not remote then
|
|
@@ -79,7 +78,7 @@ function Server.new(config: ServerConfig)
|
|
|
79
78
|
|
|
80
79
|
self._base = BaseReplion.new(Sift.Dictionary.copyDeep(config.data));
|
|
81
80
|
|
|
82
|
-
self._queuedUpdates = {} ::
|
|
81
|
+
self._queuedUpdates = {} :: BaseReplion.GenericDataTable;
|
|
83
82
|
self._isQueued = false;
|
|
84
83
|
self._destroyed = false;
|
|
85
84
|
|
|
@@ -97,7 +96,11 @@ function Server.new(config: ServerConfig)
|
|
|
97
96
|
return self;
|
|
98
97
|
end;
|
|
99
98
|
|
|
100
|
-
function Server:
|
|
99
|
+
function Server:subscribe(path: { string }?, callback: BaseReplion.Observer)
|
|
100
|
+
return self._base:subscribe(path, callback);
|
|
101
|
+
end;
|
|
102
|
+
|
|
103
|
+
function Server:observe(path: { string }?, callback: BaseReplion.Observer)
|
|
101
104
|
return self._base:observe(path, callback);
|
|
102
105
|
end;
|
|
103
106
|
|
package/src/Shared.lua
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare namespace Replion {
|
|
|
6
6
|
type Path<T> = T extends object
|
|
7
7
|
? { [K in keyof T & string]: [K] | [K, ...Path<T[K]>] }[keyof T & string]
|
|
8
8
|
: never;
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Resolves the type of the value at a specific path P within object T.
|
|
12
11
|
*/
|
|
@@ -30,6 +29,12 @@ declare namespace Replion {
|
|
|
30
29
|
get(): T;
|
|
31
30
|
get<P extends Path<T>>(path: P): PathValue<T, P>;
|
|
32
31
|
|
|
32
|
+
subscribe(key: undefined, callback: (newValue: T, oldValue: Partial<T>) => void): Cleanup;
|
|
33
|
+
subscribe<P extends Path<T>>(
|
|
34
|
+
path: P,
|
|
35
|
+
callback: (newValue: PathValue<T, P>, oldValue: PathValue<T, P> | undefined) => void,
|
|
36
|
+
): Cleanup;
|
|
37
|
+
|
|
33
38
|
observe(key: undefined, callback: (newValue: T, oldValue: Partial<T>) => void): Cleanup;
|
|
34
39
|
observe<P extends Path<T>>(
|
|
35
40
|
path: P,
|