@rbxts/scribe-fusion 2.6.0 → 2.7.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/Scribe-source-map.json +1 -1
- package/index.d.ts +11 -2
- package/init.luau +28 -8
- package/package.json +2 -2
package/Scribe-source-map.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
1
|
+
{"version":"2.7.0","format":1,"description":"Segments are [packedLine, sourceLine]. Use the last segment at or before the packed line, then add its line offset.","files":{"addons/ui/ScribeFusion.luau":{"sourceSha256":"7aacc7d1a954149f7830323b8c7d76264ffa07df2783e78a63988c0255923455","packedSha256":"7aacc7d1a954149f7830323b8c7d76264ffa07df2783e78a63988c0255923455","segments":[[1,1]],"packagePath":"init.luau"}}}
|
package/index.d.ts
CHANGED
|
@@ -9,8 +9,12 @@ declare function ScribeFusion<Scope extends unknown[], Framework extends ScribeF
|
|
|
9
9
|
): ScribeFusion.ScopedAdapter<ReturnType<Framework["Value"]>>;
|
|
10
10
|
|
|
11
11
|
declare namespace ScribeFusion {
|
|
12
|
-
type Adapter =
|
|
13
|
-
|
|
12
|
+
type Adapter =
|
|
13
|
+
/** Tracks an accessor in a Fusion value; disconnect when finished. */
|
|
14
|
+
<T>(this: void, accessor: Scribe.ReadableNode<T>) => LuaTuple<[LegacyValue<T>, () => void]>;
|
|
15
|
+
type ScopedAdapter<Value extends ScopedValue<unknown> = ScopedValue<unknown>> =
|
|
16
|
+
/** Tracks an accessor in a Fusion value and registers scope cleanup. */
|
|
17
|
+
<T>(
|
|
14
18
|
this: void,
|
|
15
19
|
accessor: Scribe.ReadableNode<T>,
|
|
16
20
|
) => LuaTuple<[Omit<Value, "set" | "_EXTREMELY_DANGEROUS_usedAsValue"> & ScopedValue<T>, () => void]>;
|
|
@@ -18,10 +22,13 @@ declare namespace ScribeFusion {
|
|
|
18
22
|
interface LegacyValue<T> {
|
|
19
23
|
readonly type: "State";
|
|
20
24
|
readonly kind: "Value";
|
|
25
|
+
/** Returns the current Fusion value. */
|
|
21
26
|
get(asDependency?: boolean): T;
|
|
27
|
+
/** Updates the Fusion value without writing to Scribe. */
|
|
22
28
|
set(value: T, force?: boolean): void;
|
|
23
29
|
}
|
|
24
30
|
interface LegacyFramework {
|
|
31
|
+
/** Creates a Fusion value with the initial value. */
|
|
25
32
|
readonly Value: <T>(this: void, initialValue: T) => LegacyValue<T>;
|
|
26
33
|
}
|
|
27
34
|
/** Public surface of a Fusion 0.3 Value. Read it through your framework's peek/use. */
|
|
@@ -30,10 +37,12 @@ declare namespace ScribeFusion {
|
|
|
30
37
|
readonly kind: "Value";
|
|
31
38
|
/** @internal Present for compatibility with Fusion's StateObject<T> inference. Do not read directly. */
|
|
32
39
|
readonly _EXTREMELY_DANGEROUS_usedAsValue: T;
|
|
40
|
+
/** Updates the Fusion value without writing to Scribe. */
|
|
33
41
|
set(value: T): void;
|
|
34
42
|
}
|
|
35
43
|
/** The 0.3 package is supplied by the caller; no separate framework is bundled. */
|
|
36
44
|
interface ScopedFramework<Scope> {
|
|
45
|
+
/** Creates a Fusion value owned by the supplied scope. */
|
|
37
46
|
readonly Value: <T>(this: void, scope: Scope, initialValue: T) => ScopedValue<T>;
|
|
38
47
|
}
|
|
39
48
|
}
|
package/init.luau
CHANGED
|
@@ -2,18 +2,38 @@
|
|
|
2
2
|
-- Fusion adapter. Copy into your game; not part of the Scribe package.
|
|
3
3
|
-- local useScribe = require(path.to.ScribeFusion)(Fusion, scope) -- 0.3
|
|
4
4
|
-- local useScribe = require(path.to.ScribeFusion)(Fusion) -- 0.2
|
|
5
|
-
-- local coins
|
|
6
|
-
--
|
|
5
|
+
-- local coins: Fusion.Value<number>, disconnect = useScribe(Data.Coins)
|
|
6
|
+
-- Annotate the value with your Fusion version's type.
|
|
7
7
|
|
|
8
8
|
export type Disconnect = () -> ()
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export type Readable<T> = {
|
|
11
|
+
--[[
|
|
12
|
+
Returns the current value.
|
|
13
|
+
]]
|
|
14
|
+
read Get: () -> T,
|
|
15
|
+
--[[
|
|
16
|
+
Runs now and on each change; returns a disconnect function.
|
|
17
|
+
]]
|
|
18
|
+
read Observe: (callback: (value: T) -> ()) -> Disconnect,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type Fusion = {
|
|
22
|
+
read Value: (...any) -> any,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type Adapter = <T>(accessor: Readable<T>) -> (any, Disconnect)
|
|
26
|
+
|
|
27
|
+
--[[
|
|
28
|
+
Creates a Fusion adapter; pass a scope for Fusion 0.3.
|
|
29
|
+
]]
|
|
30
|
+
return function(Fusion: Fusion, scope: { any }?): Adapter
|
|
31
|
+
--[[
|
|
32
|
+
Tracks an accessor and registers cleanup with the supplied scope.
|
|
33
|
+
]]
|
|
34
|
+
return function<T>(accessor: Readable<T>): (any, Disconnect)
|
|
15
35
|
local value = if scope ~= nil then Fusion.Value(scope, accessor.Get()) else Fusion.Value(accessor.Get())
|
|
16
|
-
-- Observe
|
|
36
|
+
-- Observe delivers the current value immediately.
|
|
17
37
|
local disconnect = accessor.Observe(function(new)
|
|
18
38
|
value:set(new)
|
|
19
39
|
end)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/scribe-fusion",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Optional fusion addon for Scribe",
|
|
5
5
|
"main": "init.luau",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"homepage": "https://scribe.ericplane.dev/",
|
|
13
13
|
"author": "ericplane",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@rbxts/scribe": "^2.
|
|
15
|
+
"@rbxts/scribe": "^2.7.0",
|
|
16
16
|
"@rbxts/fusion": "^0.2.0"
|
|
17
17
|
},
|
|
18
18
|
"peerDependenciesMeta": {
|