Skip to content

Experty/wait-prop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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

npm i wait-prop --save

Using

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);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%