UNPKG

1.97 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.areObservable = areObservable;
7exports.createObjectValidator = createObjectValidator;
8exports.getName = getName;
9exports.getNameOrNull = getNameOrNull;
10exports.isObservable = isObservable;
11exports.isPromise = isPromise;
12exports.isKitten = isKitten;
13exports.isStore = isStore;
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
16
17var _rx = require('rx');
18
19var _invariant = require('invariant');
20
21var _invariant2 = _interopRequireDefault(_invariant);
22
23var isFunction = _rx.helpers.isFunction;
24exports.isFunction = isFunction;
25var __DEV__ = process.env.NODE_ENV !== 'production';
26
27exports.__DEV__ = __DEV__;
28
29function areObservable(observables) {
30 return Array.isArray(observables) && observables.length > 0 && observables.reduce(function (bool, observable) {
31 return bool && isObservable(observable);
32 }, true);
33}
34
35function createObjectValidator(message) {
36 return function (obj) {
37 /* istanbul ignore else */
38 if (__DEV__) {
39 (0, _invariant2['default'])(obj && typeof obj === 'object', message, obj);
40 }
41 };
42}
43
44function getName(comp) {
45 return '' + (getNameOrNull(comp) || 'Anonymous');
46}
47
48function getNameOrNull(comp) {
49 return !!comp && (comp && comp.displayName || comp.constructor && comp.constructor.displayName || comp.fixed && comp.fixed.refs && comp.fixed.refs.displayName) || null;
50}
51
52function isObservable(observable) {
53 return observable && typeof observable.subscribe === 'function';
54}
55
56function isPromise(promise) {
57 return promise && typeof promise.then === 'function';
58}
59
60function isKitten(obj) {
61 return !!(obj && isFunction(obj.register) && isFunction(obj.getStore) && isFunction(obj.getActions));
62}
63
64function isStore(obj) {
65 return !!(obj && isFunction(obj.createRegistrar) && isFunction(obj.fromMany) && isFunction(obj.replacer) && isFunction(obj.setter) && isFunction(obj.transformer));
66}
\No newline at end of file