@rbxts/app-forge 0.6.0-alpha.21 → 0.6.0-alpha.23

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,3 +1,6 @@
1
1
  import React from "@rbxts/react";
2
2
  import type Types from "./types";
3
+ import type AppForge from ".";
4
+ export declare function createBinding(name: AppNames[number], forge: AppForge): void;
5
+ export declare function createState(name: AppNames[number], forge: AppForge): void;
3
6
  export declare function Render(props: Types.NameProps & Types.MainProps): React.ReactNode;
@@ -1,25 +1,51 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
3
  -- Packages
4
- local useBinding = TS.import(script, TS.getModule(script, "@rbxts", "react")).useBinding
4
+ local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
5
+ local useBinding = _react.useBinding
6
+ local useState = _react.useState
5
7
  -- Types
6
8
  -- Components
7
9
  local AppRegistry = TS.import(script, script.Parent, "decorator").AppRegistry
8
- local function createBinding(name, manager)
10
+ local function createBinding(name, forge)
9
11
  local _name = name
10
12
  local app = AppRegistry[_name]
11
13
  if not app then
12
14
  error(`App "{name}" not registered`)
13
15
  end
16
+ local _binds = forge.binds
17
+ local _name_1 = name
18
+ if _binds[_name_1] ~= nil then
19
+ return nil
20
+ end
14
21
  local _condition = app.visible
15
22
  if _condition == nil then
16
23
  _condition = false
17
24
  end
18
25
  local binding = { useBinding(_condition) }
19
- local _binds = manager.binds
26
+ local _binds_1 = forge.binds
27
+ local _name_2 = name
28
+ _binds_1[_name_2] = binding
29
+ end
30
+ local function createState(name, forge)
31
+ local _name = name
32
+ local app = AppRegistry[_name]
33
+ if not app then
34
+ error(`App "{name}" not registered`)
35
+ end
36
+ local _states = forge.states
20
37
  local _name_1 = name
21
- _binds[_name_1] = binding
22
- return unpack(binding)
38
+ if _states[_name_1] ~= nil then
39
+ return nil
40
+ end
41
+ local _condition = app.visible
42
+ if _condition == nil then
43
+ _condition = false
44
+ end
45
+ local state = { useState(_condition) }
46
+ local _states_1 = forge.states
47
+ local _name_2 = name
48
+ _states_1[_name_2] = state
23
49
  end
24
50
  local function Render(props)
25
51
  local names = props.names
@@ -27,7 +53,8 @@ local function Render(props)
27
53
  local forge = props.forge
28
54
  -- ▼ ReadonlyMap.forEach ▼
29
55
  local _callback = function(_, name)
30
- return createBinding(name, forge)
56
+ createBinding(name, forge)
57
+ createState(name, forge)
31
58
  end
32
59
  for _k, _v in AppRegistry do
33
60
  _callback(_v, _k, AppRegistry)
@@ -41,5 +68,7 @@ local function Render(props)
41
68
  return forge:renderAll(props)
42
69
  end
43
70
  return {
71
+ createBinding = createBinding,
72
+ createState = createState,
44
73
  Render = Render,
45
74
  }
@@ -1,11 +1,14 @@
1
1
  import React from "@rbxts/react";
2
2
  import type Types from "./types";
3
+ type Binding = [React.Binding<boolean>, (T: boolean) => void];
4
+ type State = [boolean, React.Dispatch<React.SetStateAction<boolean>>];
3
5
  export default class AppForge {
4
- binds: Map<string, [React.Binding<boolean>, (T: boolean) => void]>;
5
6
  loaded: Map<string, React.Element<any, string | React.JSXElementConstructor<any>>>;
7
+ binds: Map<string, Binding>;
8
+ states: Map<string, State>;
6
9
  private rulesManager;
7
- getBind(name: AppNames[number]): React.Binding<boolean> | undefined;
8
- getState(name: AppNames[number]): boolean | undefined;
10
+ getBind(name: AppNames[number]): React.Binding<boolean>;
11
+ getState(name: AppNames[number]): boolean;
9
12
  set(name: AppNames[number], value: boolean): void;
10
13
  open(name: AppNames[number]): void;
11
14
  close(name: AppNames[number]): void;
@@ -38,3 +41,4 @@ export default class AppForge {
38
41
  Size: UDim2;
39
42
  }, string | React.JSXElementConstructor<any>>)[];
40
43
  }
44
+ export {};
@@ -7,7 +7,10 @@ local AppContainer = TS.import(script, script, "container").AppContainer
7
7
  local AppRegistry = TS.import(script, script, "decorator").AppRegistry
8
8
  -- Classes
9
9
  local RulesManager = TS.import(script, script, "rules").default
10
- local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
10
+ -- Helpers
11
+ local _helpers = TS.import(script, script, "helpers")
12
+ local createBinding = _helpers.createBinding
13
+ local createState = _helpers.createState
11
14
  local AppForge
12
15
  do
13
16
  AppForge = setmetatable({}, {
@@ -21,35 +24,30 @@ do
21
24
  return self:constructor(...) or self
22
25
  end
23
26
  function AppForge:constructor()
24
- self.binds = {}
25
27
  self.loaded = {}
28
+ self.binds = {}
29
+ self.states = {}
26
30
  self.rulesManager = RulesManager.new(self)
27
31
  end
28
32
  function AppForge:getBind(name)
29
- local _condition = not RunService:IsRunning()
30
- if _condition then
31
- local _binds = self.binds
32
- local _name = name
33
- _condition = not (_binds[_name] ~= nil)
34
- end
35
- if _condition then
36
- return nil
37
- end
38
33
  local _binds = self.binds
39
34
  local _name = name
40
35
  if not (_binds[_name] ~= nil) then
41
- error(`App "{name}" has no binding`)
36
+ createBinding(name, self)
42
37
  end
43
38
  local _binds_1 = self.binds
44
39
  local _name_1 = name
45
40
  return _binds_1[_name_1][1]
46
41
  end
47
42
  function AppForge:getState(name)
48
- local _result = self:getBind(name)
49
- if _result ~= nil then
50
- _result = _result:getValue()
43
+ local _states = self.states
44
+ local _name = name
45
+ if not (_states[_name] ~= nil) then
46
+ createState(name, self)
51
47
  end
52
- return _result
48
+ local _states_1 = self.states
49
+ local _name_1 = name
50
+ return _states_1[_name_1][1]
53
51
  end
54
52
  function AppForge:set(name, value)
55
53
  if not self.rulesManager:applyRules(name, value) then
@@ -58,12 +56,18 @@ do
58
56
  local _binds = self.binds
59
57
  local _name = name
60
58
  local _binding = _binds[_name]
61
- local _ = _binding[1]
59
+ local _b = _binding[1]
62
60
  local setBinding = _binding[2]
61
+ local _states = self.states
62
+ local _name_1 = name
63
+ local _binding_1 = _states[_name_1]
64
+ local _s = _binding_1[1]
65
+ local setState = _binding_1[2]
63
66
  if not setBinding then
64
- error(`App "{name}" has no binding setter`)
67
+ createBinding(name, self)
65
68
  end
66
69
  setBinding(value)
70
+ setState(value)
67
71
  end
68
72
  function AppForge:open(name)
69
73
  self:set(name, true)
@@ -1,3 +1,5 @@
1
1
  import Vide from "@rbxts/vide";
2
2
  import type Types from "./types";
3
+ import type AppForge from ".";
4
+ export declare function createSource(name: AppNames[number], forge: AppForge): typeof Vide.source | undefined;
3
5
  export declare function Render(props: Types.NameProps & Types.MainProps): Vide.Node;
@@ -68,5 +68,6 @@ local function Render(props)
68
68
  return forge:renderAll(props)
69
69
  end
70
70
  return {
71
+ createSource = createSource,
71
72
  Render = Render,
72
73
  }
@@ -7,6 +7,8 @@ local AppContainer = TS.import(script, script, "container").AppContainer
7
7
  local AppRegistry = TS.import(script, script, "decorator").AppRegistry
8
8
  -- Classes
9
9
  local RulesManager = TS.import(script, script, "rules").default
10
+ -- Helpers
11
+ local createSource = TS.import(script, script, "helpers").createSource
10
12
  local AppForge
11
13
  do
12
14
  AppForge = setmetatable({}, {
@@ -28,7 +30,7 @@ do
28
30
  local _sources = self.sources
29
31
  local _name = name
30
32
  if not (_sources[_name] ~= nil) then
31
- error(`App "{name}" has no source`)
33
+ createSource(name, self)
32
34
  end
33
35
  local _sources_1 = self.sources
34
36
  local _name_1 = name
@@ -49,7 +51,7 @@ do
49
51
  local _name = name
50
52
  local source = _sources[_name]
51
53
  if not source then
52
- error(`App "{name}" has no source`)
54
+ createSource(name, self)
53
55
  end
54
56
  source(value)
55
57
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/app-forge",
3
- "version": "0.6.0-alpha.21",
3
+ "version": "0.6.0-alpha.23",
4
4
  "description": "An App Manager for react",
5
5
  "main": "out/init.lua",
6
6
  "types": "out/index.d.ts",