From 5a4ddfb642269b528fddd1299e3d9a5d7a5e2a7f Mon Sep 17 00:00:00 2001 From: Kerem Noras Date: Sat, 6 Mar 2021 12:46:28 +0300 Subject: [PATCH] perf(getter): set only true type value returns otherwise, use stork.set() manually --- package.json | 2 +- src/storken.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3a1fe49..70f44d6 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "type": "git" }, "name": "storken", - "version": "2.0.2", + "version": "2.0.3", "description": "Storken is a hook-based fully extendable and minimal state manager for React.", "author": "Kerem Noras ", "main": "dist/storken.js", diff --git a/src/storken.js b/src/storken.js index a48fa0d..42d7d77 100644 --- a/src/storken.js +++ b/src/storken.js @@ -71,7 +71,9 @@ export class Storken { ) .then(getterValue => { this.dispatchEvent('getted', getterValue, ...args) - this.set(getterValue, { force: true, disableSetter: this.opts?.disableSetterOnGetter || true }) + if (getterValue) { + this.set(getterValue, { force: true, disableSetter: this.opts?.disableSetterOnGetter || true }) + } this.load(false) return getterValue }) @@ -139,8 +141,8 @@ export class Storken { Promise.resolve( typeof this.opts.setter === 'function' ? typeof this.opts.setter?.then === 'function' - ? await this.opts.setter(this, ...this?.args) - : this.opts.setter(this, ...this?.args) + ? await this.opts.setter(this, ...this?.args) + : this.opts.setter(this, ...this?.args) : this.opts.setter ) .then(() => { this.load(false) })