From 9d118275d393e99be9de6798b481721515d8aef8 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 28 Oct 2019 11:12:36 -0400 Subject: [PATCH] add has_prop helper --- src/runtime/internal/Component.ts | 4 ++-- src/runtime/internal/dom.ts | 4 +++- src/runtime/internal/utils.ts | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 9e0c2e58f2..3855d3c361 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -1,6 +1,6 @@ import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler'; import { current_component, set_current_component } from './lifecycle'; -import { blank_object, is_function, run, run_all, noop } from './utils'; +import { blank_object, is_function, run, run_all, noop, has_prop } from './utils'; import { children } from './dom'; import { transition_in } from './transitions'; @@ -22,7 +22,7 @@ interface T$$ { } export function bind(component, name, callback) { - if (component.$$.props.hasOwnProperty(name)) { + if (has_prop(component.$$.props, name)) { name = component.$$.props[name] || name; component.$$.bound[name] = callback; callback(component.$$.ctx[name]); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index c60f437863..e4db8c1e15 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -1,3 +1,5 @@ +import { has_prop } from "./utils"; + export function append(target: Node, node: Node) { target.appendChild(node); } @@ -29,7 +31,7 @@ export function object_without_properties(obj: T, exclude: const target = {} as Pick>; for (const k in obj) { if ( - Object.prototype.hasOwnProperty.call(obj, k) + has_prop(obj, k) // @ts-ignore && exclude.indexOf(k) === -1 ) { diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index d267b73cee..6816f8684a 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -105,3 +105,5 @@ export function set_store_value(store, ret, value = ret) { store.set(value); return ret; } + +export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); \ No newline at end of file