-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapPropsStream.js
73 lines (57 loc) · 2.27 KB
/
mapPropsStream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = exports.mapPropsStreamWithConfig = void 0;
var _symbolObservable = _interopRequireDefault(require("symbol-observable"));
var _createFactory = _interopRequireDefault(require("./utils/createFactory"));
var _componentFromStream = require("./componentFromStream");
var _setDisplayName = _interopRequireDefault(require("./setDisplayName"));
var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName"));
var _setObservableConfig = require("./setObservableConfig");
var identity = function identity(t) {
return t;
};
var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config) {
var componentFromStream = (0, _componentFromStream.componentFromStreamWithConfig)({
fromESObservable: identity,
toESObservable: identity
});
return function (transform) {
return function (BaseComponent) {
var factory = (0, _createFactory.default)(BaseComponent);
var fromESObservable = config.fromESObservable,
toESObservable = config.toESObservable;
return componentFromStream(function (props$) {
var _ref;
return _ref = {
subscribe: function subscribe(observer) {
var subscription = toESObservable(transform(fromESObservable(props$))).subscribe({
next: function next(childProps) {
return observer.next(factory(childProps));
}
});
return {
unsubscribe: function unsubscribe() {
return subscription.unsubscribe();
}
};
}
}, _ref[_symbolObservable.default] = function () {
return this;
}, _ref;
});
};
};
};
exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig;
var mapPropsStream = function mapPropsStream(transform) {
var hoc = mapPropsStreamWithConfig(_setObservableConfig.config)(transform);
if (process.env.NODE_ENV !== 'production') {
return function (BaseComponent) {
return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent));
};
}
return hoc;
};
var _default = mapPropsStream;
exports.default = _default;