-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathReact.luau
More file actions
154 lines (141 loc) · 6.18 KB
/
React.luau
File metadata and controls
154 lines (141 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
--!strict
-- ROBLOX upstream: https://github.com/facebook/react/blob/56e9feead0f91075ba0a4f725c9e4e343bca1c67/packages/react/src/React.js
--[[*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*]]
local LuauPolyfill = require("@pkg/@jsdotlua/luau-polyfill")
type Object = LuauPolyfill.Object
local createMutableSource = require("./ReactMutableSource")
local ReactSharedInternals = require("@pkg/@jsdotlua/shared").ReactSharedInternals
local ReactBaseClasses = require("./ReactBaseClasses")
local ReactChildren = require("./ReactChildren")
local ReactElementValidator = require("./ReactElementValidator")
local ReactElement = require("./ReactElement")
local ReactCreateRef = require("./ReactCreateRef")
local ReactForwardRef = require("./ReactForwardRef")
local ReactHooks = require("./ReactHooks")
local ReactMemo = require("./ReactMemo")
local ReactContext = require("./ReactContext")
local ReactLazy = require("./ReactLazy")
type LazyComponent<T, P> = ReactLazy.LazyComponent<T, P>
-- ROBLOX DEVIATION: Bindings
local ReactBinding = require("./ReactBinding.roblox.luau")
-- ROBLOX DEVIATION: Re-export `None` marker
local ReactNone = require("./None.roblox.luau")
local SharedModule = require("@pkg/@jsdotlua/shared")
local ReactSymbols = SharedModule.ReactSymbols
local shouldValidate = _G.__DEV__ or _G.__DISABLE_ALL_WARNINGS_EXCEPT_PROP_VALIDATION__
local ReactTypes = require("@pkg/@jsdotlua/shared")
export type React_StatelessFunctionalComponent<P> =
ReactTypes.React_StatelessFunctionalComponent<P>
export type React_ComponentType<P> = ReactTypes.React_ComponentType<P>
type React_AbstractComponent<P, T> = ReactTypes.React_AbstractComponent<P, T>
export type React_ElementProps<ElementType> = ReactTypes.React_ElementProps<ElementType>
export type ReactElement<P = Object, T = any> = ReactTypes.ReactElement<P, T>
export type ReactContext<T> = ReactTypes.ReactContext<T>
export type ReactProviderType<T> = ReactTypes.ReactProviderType<T>
export type React_Node = ReactTypes.React_Node
export type PureComponent<Props, State = nil> = ReactTypes.React_PureComponent<
Props,
State
>
-- ROBLOX deviation START: bindings support
export type ReactBinding<T> = ReactTypes.ReactBinding<T>
export type ReactBindingUpdater<T> = ReactTypes.ReactBindingUpdater<T>
-- ROBLOX deviation END
type createElementFn = <P, T>(
type_: React_StatelessFunctionalComponent<P>
| React_ComponentType<P>
| React_AbstractComponent<P, T>
| string
| ReactContext<any>
| ReactProviderType<any>
| LazyComponent<T, P>,
props: P?,
...(React_Node | (...any) -> React_Node)
) -> ReactElement<P, T>
type cloneElementFn = <P, T>(
element: ReactElement<P, T>,
config: P?,
...React_Node
) -> ReactElement<P, T>
-- ROBLOX FIXME Luau: these yield Cannot call non-function because the identical unions don't collapse
-- ROBLOX FIXME Luau: the next step is to add createElementFn here and work through issues, AFTER normalization and type packs work
local createElement = if shouldValidate
then ReactElementValidator.createElementWithValidation :: createElementFn
else ReactElement.createElement :: createElementFn
local cloneElement: cloneElementFn = if shouldValidate
then ReactElementValidator.cloneElementWithValidation :: cloneElementFn
else ReactElement.cloneElement :: cloneElementFn
return {
Children = ReactChildren,
createMutableSource = createMutableSource,
createRef = ReactCreateRef.createRef,
Component = ReactBaseClasses.Component,
PureComponent = ReactBaseClasses.PureComponent,
createContext = ReactContext.createContext,
forwardRef = ReactForwardRef.forwardRef,
lazy = ReactLazy.lazy,
memo = ReactMemo.memo,
useCallback = ReactHooks.useCallback,
useContext = ReactHooks.useContext,
useEffect = ReactHooks.useEffect,
useImperativeHandle = ReactHooks.useImperativeHandle,
useDebugValue = ReactHooks.useDebugValue,
useLayoutEffect = ReactHooks.useLayoutEffect,
useMemo = ReactHooks.useMemo,
useMutableSource = ReactHooks.useMutableSource,
useReducer = ReactHooks.useReducer,
useRef = ReactHooks.useRef,
-- ROBLOX deviation: bindings support
useBinding = ReactHooks.useBinding,
useState = ReactHooks.useState,
Fragment = ReactSymbols.REACT_FRAGMENT_TYPE,
Profiler = ReactSymbols.REACT_PROFILER_TYPE,
StrictMode = ReactSymbols.REACT_STRICT_MODE_TYPE,
unstable_DebugTracingMode = ReactSymbols.REACT_DEBUG_TRACING_MODE_TYPE,
Suspense = ReactSymbols.REACT_SUSPENSE_TYPE,
createElement = createElement,
cloneElement = cloneElement,
isValidElement = ReactElement.isValidElement,
-- ROBLOX TODO: ReactVersion
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals,
-- Deprecated behind disableCreateFactory
-- ROBLOX TODO: createFactory,
-- Concurrent Mode
-- ROBLOX TODO: useTransition,
-- ROBLOX TODO: startTransition,
-- ROBLOX TODO: useDeferredValue,
-- ROBLOX TODO: REACT_SUSPENSE_LIST_TYPE as SuspenseList,
unstable_LegacyHidden = ReactSymbols.REACT_LEGACY_HIDDEN_TYPE,
-- enableBlocksAPI
-- ROBLOX TODO: block,
-- enableFundamentalAPI
-- ROBLOX TODO: createFundamental as unstable_createFundamental,
-- enableScopeAPI
-- ROBLOX TODO: REACT_SCOPE_TYPE as unstable_Scope,
-- ROBLOX TODO: useOpaqueIdentifier as unstable_useOpaqueIdentifier,
-- ROBLOX deviation START: bindings support
createBinding = ReactBinding.create,
joinBindings = ReactBinding.join,
-- ROBLOX deviation END
-- ROBLOX DEVIATION: export the `None` placeholder for use with setState
None = ReactNone,
-- ROBLOX FIXME: These aren't supposed to be exposed, but they're needed by
-- the renderer in order to update properly
__subscribeToBinding = ReactBinding.subscribe,
-- ROBLOX DEVIATION: export Change, Event, Tag and Attributes from React
Event = require("@pkg/@jsdotlua/shared").Event,
Change = require("@pkg/@jsdotlua/shared").Change,
Tag = require("@pkg/@jsdotlua/shared").Tag,
Attributes = require("@pkg/@jsdotlua/shared").Attributes,
-- ROBLOX DEVIATION: used by error reporters to parse caught errors. React
-- stringifies at its boundaries to maintain compatibility with
-- ScriptContext signals that may ultimately catch them
unstable_parseReactError = require("@pkg/@jsdotlua/shared").parseReactError,
}