UNPKG

thundercats

Version:
66 lines (51 loc) 1.97 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); exports.areObservable = areObservable; exports.createObjectValidator = createObjectValidator; exports.getName = getName; exports.getNameOrNull = getNameOrNull; exports.isObservable = isObservable; exports.isPromise = isPromise; exports.isKitten = isKitten; exports.isStore = isStore; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _rx = require('rx'); var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant); var isFunction = _rx.helpers.isFunction; exports.isFunction = isFunction; var __DEV__ = process.env.NODE_ENV !== 'production'; exports.__DEV__ = __DEV__; function areObservable(observables) { return Array.isArray(observables) && observables.length > 0 && observables.reduce(function (bool, observable) { return bool && isObservable(observable); }, true); } function createObjectValidator(message) { return function (obj) { /* istanbul ignore else */ if (__DEV__) { (0, _invariant2['default'])(obj && typeof obj === 'object', message, obj); } }; } function getName(comp) { return '' + (getNameOrNull(comp) || 'Anonymous'); } function getNameOrNull(comp) { return !!comp && (comp && comp.displayName || comp.constructor && comp.constructor.displayName || comp.fixed && comp.fixed.refs && comp.fixed.refs.displayName) || null; } function isObservable(observable) { return observable && typeof observable.subscribe === 'function'; } function isPromise(promise) { return promise && typeof promise.then === 'function'; } function isKitten(obj) { return !!(obj && isFunction(obj.register) && isFunction(obj.getStore) && isFunction(obj.getActions)); } function isStore(obj) { return !!(obj && isFunction(obj.createRegistrar) && isFunction(obj.fromMany) && isFunction(obj.replacer) && isFunction(obj.setter) && isFunction(obj.transformer)); }