UNPKG

@web-native-js/observer

Version:

A simple set of functions for intercepting and observing JavaScript objects and arrays.

37 lines (34 loc) 1.14 kB
/** * @imports */ import _isFunction from '@webqit/util/js/isFunction.js'; import _isTypeObject from '@webqit/util/js/isTypeObject.js'; import _getType from '@webqit/util/js/getType.js'; import getInterceptors from './getInterceptors.js'; /** * Removes traps from an subject's firebase. * * @param array|object subject * @param string|array|function filter * @param function originalHandler * @param object params * * @return void */ export default function(subject, filter, originalHandler = null, params = {}) { if (!subject || !_isTypeObject(subject)) { throw new Error('Object must be of type subject; "' + _getType(subject) + '" given!'); } if (_isFunction(filter)) { params = arguments.length > 2 ? originalHandler : {}; originalHandler = filter; filter = null; } if (originalHandler && !_isFunction(originalHandler)) { throw new Error('Handler must be a function; "' + _getType(originalHandler) + '" given!'); } var interceptors; if (interceptors = getInterceptors(subject, false)) { return interceptors.forget({filter, originalHandler, params,}); } }