@@ -112,13 +112,13 @@ npm install --save-prod react-executor
112112
113113# Introduction
114114
115- An executor executes a task, stores the execution result, and provides access to it . Tasks are callbacks that return a
116- value or throw an error.
115+ An executor runs a task, stores the execution result, and provides access to that result . Tasks are callbacks that
116+ return a value or throw an error.
117117
118118An [ ` Executor ` ] ( https://smikhalevski.github.io/react-executor/interfaces/react-executor.Executor.html ) is created and
119119managed by
120- an [ ` ExecutorManager ` ] ( https://smikhalevski.github.io/react-executor/classes/react-executor.ExecutorManager.html )
121- which controls the executor lifecycle:
120+ an [ ` ExecutorManager ` ] ( https://smikhalevski.github.io/react-executor/classes/react-executor.ExecutorManager.html ) ,
121+ which controls the executor's lifecycle:
122122
123123``` ts
124124import { ExecutorManager } from ' react-executor' ;
@@ -129,12 +129,12 @@ const rookyExecutor = manager.getOrCreate('rooky');
129129// ⮕ Executor<any>
130130```
131131
132- Each executor has a unique key in the scope of the manager. Here we created the new executor with the key ` 'rooky' ` .
133- Managers create a new executor when you call
132+ Each executor has a unique key within the manager's scope. In this example, we created a new executor with the key
133+ ` 'rooky' ` . The manager creates a new executor when you call
134134[ ` getOrCreate ` ] ( https://smikhalevski.github.io/react-executor/classes/react-executor.ExecutorManager.html#getorcreate )
135- with a new key. Each consequent call with that key returns the same executor.
135+ with a previously unused key. Subsequent calls with the same key return the same executor instance .
136136
137- If you want to retrieve an existing executor by its key and don't want to create a new executor if it doesn't exist, use
137+ If you want to retrieve an existing executor by its key and avoid creating a new one if it doesn't exist, use
138138[ ` get ` ] ( https://smikhalevski.github.io/react-executor/classes/react-executor.ExecutorManager.html#get ) :
139139
140140``` ts
@@ -145,7 +145,7 @@ manager.get('rooky');
145145// ⮕ Executor<any>
146146```
147147
148- The executor we created is unsettled, which means it neither stores a value, nor a task failure reason:
148+ The executor we created is _ unsettled _ , meaning it stores neither a value nor a failure reason:
149149
150150``` ts
151151rookyExecutor .isSettled ;
@@ -168,19 +168,19 @@ bobbyExecutor.value;
168168// ⮕ 42
169169```
170170
171- An initial value can be a task which is executed, a promise which the executor awaits , or any other value that instantly
172- fulfills the executor. Read more in the [ Execute a task] ( #execute-a-task ) and in
171+ An initial value may be a task ( which will be executed) , a promise ( which the executor will await) , or any other value
172+ that immediately fulfills the executor. Read more in the [ Execute a task] ( #execute-a-task ) and in
173173the [ Settle an executor] ( #settle-an-executor ) sections.
174174
175- When an executor is created , you can provide an array of plugins:
175+ When creating an executor, you can also provide an array of plugins:
176176
177177``` ts
178178import retryRejected from ' react-executor/plugin/retryRejected' ;
179179
180180const rookyExecutor = manager .getOrCreate (' rooky' , 42 , [retryRejected ()]);
181181```
182182
183- Plugins can subscribe to [ executor events] ( #events-and-lifecycle ) or alter the executor instance. Read more about
183+ Plugins can subscribe to [ executor events] ( #events-and-lifecycle ) or modify the executor instance. Read more about
184184plugins in the [ Plugins] ( #plugins ) section.
185185
186186## Executor keys
@@ -2215,24 +2215,20 @@ To detect a global pending state we can rely on events published by
22152215an [ ` ExecutorManager ` ] ( https://smikhalevski.github.io/react-executor/classes/react-executor.ExecutorManager.html ) :
22162216
22172217``` ts
2218- function useGlobalPending (predicate = (executor : Executor ) => true ): boolean {
2218+ function useIsPending (predicate = (executor : Executor ) => true ): boolean {
22192219 const manager = useExecutorManager ();
22202220 const [isPending, setPending] = useState (false );
22212221
22222222 useEffect (() => {
2223- const listener = (event : ExecutorEvent ) => {
2224- setPending (
2225- Array .from (manager )
2226- .filter (predicate )
2227- .some (executor => executor .isPending )
2228- );
2223+ const syncIsPending = (event : ExecutorEvent ) => {
2224+ setPending (Array .from (manager ).some (executor => predicate (executor ) && executor .isPending ));
22292225 };
22302226
22312227 // 1️⃣ Ensure isPending is up-to-date after mount
2232- listener ();
2228+ syncIsPending ();
22332229
22342230 // 2️⃣ Sync isPending when any event is published
2235- return manager .subscribe (listener );
2231+ return manager .subscribe (syncIsPending );
22362232 }, [manager ]);
22372233
22382234 return isPending ;
@@ -2242,7 +2238,7 @@ function useGlobalPending(predicate = (executor: Executor) => true): boolean {
22422238Now a global pending indicator can be shown when _ any_ executor is pending:
22432239
22442240``` tsx
2245- const isPending = useGlobalPending ();
2241+ const isPending = useIsPending ();
22462242
22472243isPending && <LoadingIndicator />;
22482244```
@@ -2254,17 +2250,14 @@ be marked as such, for example with an annotation:
22542250const accountExecutor = useExecutor (
22552251 ' account' ,
22562252
2257- async () => {
2258- const response = await fetch (' /account' );
2259- return response .json ();
2260- },
2253+ () => fetch (' /account' ),
22612254
22622255 // 1️⃣ Annotate an executor once via a plugin
22632256 [executor => executor .annotate ({ isFetching: true })]
22642257);
22652258
22662259// 2️⃣ Get global pending status for executors that are fetching data
2267- const isPending = useGlobalPending (executor => executor .annotations .isFetching );
2260+ const isPending = useIsPending (executor => executor .annotations .isFetching );
22682261```
22692262
22702263<!-- /ARTICLE-->
0 commit comments