https://github.com/gkucmierz/wait-prop
https://github.com/gkucmierz/wait-prop
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gkucmierz/wait-prop
- Owner: gkucmierz
- Created: 2020-06-27T23:42:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T09:58:47.000Z (over 2 years ago)
- Last Synced: 2025-05-22T04:39:47.119Z (25 days ago)
- Language: TypeScript
- Size: 95.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wait-prop
### Motivation
Sometimes there is need to use not corectly prepared **library** or there is need to **wait** for **properties** that will **appear** in some object in not specified time in future.
Using [Proxy](https://developer.mozilla.org/pl/docs/Web/JavaScript/Referencje/Obiekty/Proxy) is **not solving** problem if we are waiting for properties in **window** object for example.
This function **solves** this problem a little dirty, but **effective** way.
### Install
```bash
npm i wait-prop --save
```### Using
```js
import { waitProp } from 'wait-prop';const getGlobal = () => window || this;
// wait for library
waitProp(getGlobal(), 'exampleLib').then(lib => {
console.log('Library loaded:', lib);
});// simulate loading library after 1 second
setTimeout(() => {
getGlobal().exampleLib = {
exampleMethod: () => []
};
}, 1e3);
```