diff --git a/lib/Capsule.ts b/lib/Capsule.ts index 1f9d604..92e6ccf 100644 --- a/lib/Capsule.ts +++ b/lib/Capsule.ts @@ -13,7 +13,7 @@ export interface ICapsule { } export function isCapsule(maybeCapsule: any): maybeCapsule is ICapsule { - return typeof maybeCapsule.val !== "undefined" + return maybeCapsule && typeof maybeCapsule.val !== "undefined" && typeof maybeCapsule.watch === "function" && typeof maybeCapsule.toString === "function"; } @@ -42,8 +42,8 @@ export default class Capsule implements ICapsule this.isString = typeof val === "string"; } - static new(val: T | Capsule): Capsule { - if (val instanceof Capsule) { + static new(val: T | ICapsule): ICapsule { + if (isCapsule(val)) { return val; } else { return new Capsule(val); diff --git a/lib/Publisher.ts b/lib/Publisher.ts index d40c4ab..b555300 100644 --- a/lib/Publisher.ts +++ b/lib/Publisher.ts @@ -1,4 +1,4 @@ -import ISubscriber, {LEvent} from "./Subscriber"; +import { ISubscriber, LEvent } from "./Subscriber"; class PublisherSubscription implements ISubscription { private subscriber: ISubscriber; diff --git a/package.json b/package.json index 64fdee6..fc4621f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@djledda/ladder", - "version": "1.0.1", + "version": "1.0.2", "description": "other libraries provide you with a whole framework - this is just a ladder", "author": "Daniel Ledda ", "license": "MIT",