MCPcopy Create free account
hub / github.com/async-library/react-async / constructor

Method constructor

packages/react-async/src/Async.tsx:106–148  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

104 private dispatch: (action: AsyncAction<T>, ...args: any[]) => void
105
106 constructor(props: Props) {
107 super(props)
108
109 this.start = this.start.bind(this)
110 this.load = this.load.bind(this)
111 this.run = this.run.bind(this)
112 this.cancel = this.cancel.bind(this)
113 this.onResolve = this.onResolve.bind(this)
114 this.onReject = this.onReject.bind(this)
115 this.setData = this.setData.bind(this)
116 this.setError = this.setError.bind(this)
117
118 const promise = props.promise
119 const promiseFn = props.promiseFn || defaultOptions.promiseFn
120 const initialValue = props.initialValue || defaultOptions.initialValue
121
122 this.state = {
123 ...init<T>({ initialValue, promise, promiseFn }),
124 cancel: this.cancel,
125 run: this.run,
126 reload: () => {
127 this.load()
128 this.run(...this.args)
129 },
130 setData: this.setData,
131 setError: this.setError,
132 }
133 this.debugLabel = props.debugLabel || defaultOptions.debugLabel
134
135 const { devToolsDispatcher } = globalScope.__REACT_ASYNC__
136 const _reducer = props.reducer || defaultOptions.reducer
137 const _dispatcher = props.dispatcher || defaultOptions.dispatcher || devToolsDispatcher
138 const reducer: (
139 state: ReducerAsyncState<T>,
140 action: AsyncAction<T>
141 ) => ReducerAsyncState<T> = _reducer
142 ? (state, action) => _reducer(state, action, asyncReducer)
143 : asyncReducer
144 const dispatch = dispatchMiddleware<T>((action, callback) => {
145 this.setState(state => reducer(state, action), callback)
146 })
147 this.dispatch = _dispatcher ? action => _dispatcher(action, dispatch, props) : dispatch
148 }
149
150 componentDidMount() {
151 this.mounted = true

Callers

nothing calls this directly

Calls 5

loadMethod · 0.95
runMethod · 0.95
initFunction · 0.90
dispatchMiddlewareFunction · 0.90
reducerFunction · 0.90

Tested by

no test coverage detected