From cfa15ccbb50400c5a084c94108f1b21b8cea9a64 Mon Sep 17 00:00:00 2001 From: Ian K Smith Date: Fri, 23 Aug 2019 11:31:58 -0600 Subject: [PATCH 1/2] Check if target element is 'null' + call 'destroy' on error --- package.json | 6 +++--- src/lib.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 71a304b..866ea53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "watch-resize", - "version": "2.0.0", + "version": "2.0.1", "description": "Watch any DOM element for size changes using Observables.", "author": "Ian K Smith ", "license": "MIT", @@ -19,8 +19,8 @@ "build": "npm-run-all -s clean:dist -p compile:*", "compile:cjs": "microbundle build src/index.cjs.ts --format cjs --external rxjs", "compile:umd": "microbundle build src/index.umd.ts --format umd --name watchResize --external rxjs", - "compile_watch:cjs": "microbundle watch src/index.cjs.ts --format cjs", - "compile_watch:umd": "microbundle watch src/index.umd.ts --format umd --name watchResize", + "compile_watch:cjs": "microbundle watch src/index.cjs.ts --format cjs --external none", + "compile_watch:umd": "microbundle watch src/index.umd.ts --format umd --name watchResize --external none", "clean": "npm-run-all -s clean:*", "clean:dist": "rimraf dist", "clean:cache": "rimraf .rts2_cache_*", diff --git a/src/lib.ts b/src/lib.ts index fbaf1e3..e46269e 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -53,7 +53,7 @@ export function watchResize( ): Promise<[WatchResizeObservable, DestroyWatchResizeObservable]> { return new Promise((resolve, reject) => { // Assert that `element` is defined and is a valid DOM node. - if (typeof element === 'undefined') { + if (typeof element === 'undefined' || element === null) { reject('[watch-resize] The given element must be defined.'); } if (!isElement(element)) { @@ -118,6 +118,7 @@ export function watchResize( resolve([observable, destroy]); } else { + destroy(); reject('[watch-resize] Failed to build a nested browsing context.'); } }); From 05cade6c7842f595fae8577fac42384a7f74f109 Mon Sep 17 00:00:00 2001 From: Ian K Smith Date: Fri, 23 Aug 2019 12:22:31 -0600 Subject: [PATCH 2/2] Update README.md --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ba9e54..37df863 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,27 @@ A cross-compatible [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web ## 🔗 Installation -Install via `yarn` (recommended): +Install via `yarn` or `npm`: ```sh yarn add watch-resize ``` -Install via `npm`: - ```sh npm install watch-resize ``` +Don't forget the `peerDependencies`: + +```sh +yarn add rxjs@~6.5.2 +``` + +```sh +npm install rxjs@~6.5.2 +``` + + ## 🛠️ Usage ```ts