forked from topcoder-platform/topcoder-react-utils
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,618 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
__tests__/shared/components/CodeSplit/__assets__/SampleCodeSplit.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
__tests__/shared/utils/splitComponent/__assets__/SampleCodeSplit.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* This is a sample component, doing a code split. | ||
*/ | ||
|
||
import { useGlobalState } from '@dr.pogodin/react-global-state'; | ||
|
||
import splitComponent from 'utils/splitComponent'; | ||
import { requireWeak } from 'utils/webpack'; | ||
|
||
function Placeholder() { | ||
return <div>PLACEHOLDER!</div>; | ||
} | ||
|
||
const SampleComponent1 = splitComponent({ | ||
chunkName: 'sample-component-1', | ||
getClientSide: () => import( | ||
/* webpackChunkName: 'sample-component-1' */ './SampleComponent' | ||
), | ||
}); | ||
|
||
const SampleComponent2 = splitComponent({ | ||
chunkName: 'sample-component-2', | ||
getClientSide: () => import( | ||
/* webpackChunkName: 'sample-component-2' */ './SampleComponent' | ||
), | ||
placeholder: Placeholder, | ||
}); | ||
|
||
const SampleComponent3 = splitComponent({ | ||
chunkName: 'sample-component-3', | ||
getClientSide: () => import( | ||
/* webpackChunkName: 'sample-component-3' */ './SampleComponent' | ||
), | ||
placeholder: Placeholder, | ||
serverSide: requireWeak('./SampleComponent', __dirname), | ||
}); | ||
|
||
export default function SampleCodeSplit() { | ||
const [testKey] = useGlobalState('test.key', 'testValue'); | ||
return ( | ||
<> | ||
<h1>{testKey}</h1> | ||
<SampleComponent1 /> | ||
<SampleComponent2 /> | ||
<SampleComponent3 /> | ||
</> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Semaphore | ||
```jsx | ||
import { Semaphore } from '@dr.pogodin/react-utils'; | ||
``` | ||
The [Semaphore] class implements a synchronization primitive which allows | ||
an async code to wait until the semaphore is set to the "ready" state, if | ||
it is not in that state already. A semaphore can be switched between "ready" | ||
and "non-ready" states as needed. | ||
|
||
## Methods | ||
- [constructor()] - Creates a new [Semaphore] instance. | ||
- [setReady()] - Sets semaphore to the specified state. | ||
- [waitReady()] - Creates a [Promise] which resolves as soon as the semaphore | ||
is in "ready" state. | ||
|
||
### constructor() | ||
```jsx | ||
const semaphore = new Semaphore(ready = false); | ||
``` | ||
Creates a new [Semaphore] instance. | ||
|
||
**Arguments** | ||
- `ready` - **boolean** - Optional. The initial semaphore state. Defaults **false**. | ||
|
||
### setReady() | ||
```jsx | ||
semaphore.setReady(ready); | ||
``` | ||
Sets semaphore to the specified state. | ||
|
||
**Arguments** | ||
- `ready` - **boolean** - Target state. | ||
|
||
### waitReady() | ||
```jsx | ||
semaphore.waitReady(): Promise; | ||
``` | ||
Creates a [Promise] which resolves as soon as the semaphore is in the "ready" | ||
state. | ||
|
||
Note that unlike [Barrier] instances, a semaphore does not resolve all | ||
pending [waitReady()] promises immediately when switched to "ready" state. | ||
Setting a semaphore to "ready" will trigger an attempt to _synchronously_ | ||
resolve each pending [waitReady()] promise for that semaphore, for each of | ||
these promises the actual state of the semaphore at the moment of resolution | ||
attempt will be tested, and if it has switched back to "non-ready", the promise | ||
will remain pending until the next resolution chance. Thus, a semaphore can | ||
be used as [mutex], if each asynchronous code waiting for a semaphore sets it | ||
back to "non-ready" state as soon as it resolved. | ||
|
||
## Properties | ||
- `semaphore.ready` - **boolean** - Read-only. Current semaphore state. | ||
|
||
<!-- Re-usable links below --> | ||
|
||
[Barrier]: /docs/api/classes/Barrier | ||
[constructor()]: #constructor | ||
[mutex]: https://en.wikipedia.org/wiki/Mutual_exclusion | ||
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise | ||
[Semaphore]: /docs/api/classes/Semaphore | ||
[setReady()]: #setready | ||
[waitReady()]: #waitready |
Oops, something went wrong.