https://github.com/kyza/gsetw
The fastest object node waiter possible.
https://github.com/kyza/gsetw
javascript javascript-library
Last synced: about 1 month ago
JSON representation
The fastest object node waiter possible.
- Host: GitHub
- URL: https://github.com/kyza/gsetw
- Owner: Kyza
- License: mit
- Created: 2021-03-21T00:46:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-26T19:35:53.000Z (about 5 years ago)
- Last Synced: 2025-01-25T21:11:23.505Z (over 1 year ago)
- Topics: javascript, javascript-library
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gsetw
The fastest object node waiter possible.
## Beware
This function was created for a *very* specific use case--intercepting and patching the `push` function of a `webpackJsonp` object--and is therefore fragile and has many caveats.
Only use this if you *absolutely need* the fastest response possible.
## Usage
```js
const gsetw = require("gsetw");
let obj = {};
gsetw(obj, "test.0.bruh", true).then(node => {
// gsetw(..., ..., true), so it prints before the node on the object is set.
console.log(obj.test); // undefined
});
setTimeout(() => {
// Setting the node on the object like this will trigger the waiter.
obj.test = [{ bruh: "fhdsk" }];
}, 1e3);
```
## Parameters
### `gsetw(object, nodePath, before = false)`
- `object` - `object` - The parent object of the node you want to wait for.
- `nodePath` - `string` - `"the.path.to.the.node"`. Can be any depth, though the deeper it is the more fragile it is.
- `before` - `boolean` - Whether to resolve the promise before or after the object is set.