1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Cycle = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 | "use strict";
|
3 |
|
4 | var base_1 = require('@cycle/base');
|
5 | var rx_adapter_1 = require('@cycle/rx-adapter');
|
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 | var Cycle = function Cycle(main, drivers) {
|
34 | return base_1.default(main, drivers, { streamAdapter: rx_adapter_1.default });
|
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 | function run(main, drivers) {
|
63 | var run = base_1.default(main, drivers, { streamAdapter: rx_adapter_1.default }).run;
|
64 | return run();
|
65 | }
|
66 | exports.run = run;
|
67 | Cycle.run = run;
|
68 | Object.defineProperty(exports, "__esModule", { value: true });
|
69 | exports.default = Cycle;
|
70 |
|
71 |
|
72 | },{"@cycle/base":2,"@cycle/rx-adapter":3}],2:[function(require,module,exports){
|
73 | "use strict";
|
74 |
|
75 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
76 |
|
77 | function logToConsoleError(err) {
|
78 | var target = err.stack || err;
|
79 | if (console && console.error) {
|
80 | console.error(target);
|
81 | } else if (console && console.log) {
|
82 | console.log(target);
|
83 | }
|
84 | }
|
85 | function makeSinkProxies(drivers, streamAdapter) {
|
86 | var sinkProxies = {};
|
87 | for (var name_1 in drivers) {
|
88 | if (drivers.hasOwnProperty(name_1)) {
|
89 | var holdSubject = streamAdapter.makeSubject();
|
90 | var driverStreamAdapter = drivers[name_1].streamAdapter || streamAdapter;
|
91 | var stream = driverStreamAdapter.adapt(holdSubject.stream, streamAdapter.streamSubscribe);
|
92 | sinkProxies[name_1] = {
|
93 | stream: stream,
|
94 | observer: holdSubject.observer
|
95 | };
|
96 | }
|
97 | }
|
98 | return sinkProxies;
|
99 | }
|
100 | function callDrivers(drivers, sinkProxies, streamAdapter) {
|
101 | var sources = {};
|
102 | for (var name_2 in drivers) {
|
103 | if (drivers.hasOwnProperty(name_2)) {
|
104 | var driverOutput = drivers[name_2](sinkProxies[name_2].stream, streamAdapter, name_2);
|
105 | var driverStreamAdapter = drivers[name_2].streamAdapter;
|
106 | if (driverStreamAdapter && driverStreamAdapter.isValidStream(driverOutput)) {
|
107 | sources[name_2] = streamAdapter.adapt(driverOutput, driverStreamAdapter.streamSubscribe);
|
108 | } else {
|
109 | sources[name_2] = driverOutput;
|
110 | }
|
111 | }
|
112 | }
|
113 | return sources;
|
114 | }
|
115 | function replicateMany(sinks, sinkProxies, streamAdapter) {
|
116 | var results = Object.keys(sinks).filter(function (name) {
|
117 | return !!sinkProxies[name];
|
118 | }).map(function (name) {
|
119 | return streamAdapter.streamSubscribe(sinks[name], {
|
120 | next: function next(x) {
|
121 | sinkProxies[name].observer.next(x);
|
122 | },
|
123 | error: function error(err) {
|
124 | logToConsoleError(err);
|
125 | sinkProxies[name].observer.error(err);
|
126 | },
|
127 | complete: function complete(x) {
|
128 | sinkProxies[name].observer.complete(x);
|
129 | }
|
130 | });
|
131 | });
|
132 | var disposeFunctions = results.filter(function (dispose) {
|
133 | return typeof dispose === 'function';
|
134 | });
|
135 | return function () {
|
136 | disposeFunctions.forEach(function (dispose) {
|
137 | return dispose();
|
138 | });
|
139 | };
|
140 | }
|
141 | function disposeSources(sources) {
|
142 | for (var k in sources) {
|
143 | if (sources.hasOwnProperty(k) && sources[k] && typeof sources[k].dispose === 'function') {
|
144 | sources[k].dispose();
|
145 | }
|
146 | }
|
147 | }
|
148 | var isObjectEmpty = function isObjectEmpty(obj) {
|
149 | return Object.keys(obj).length === 0;
|
150 | };
|
151 | function Cycle(main, drivers, options) {
|
152 | if (typeof main !== "function") {
|
153 | throw new Error("First argument given to Cycle must be the 'main' " + "function.");
|
154 | }
|
155 | if ((typeof drivers === 'undefined' ? 'undefined' : _typeof(drivers)) !== "object" || drivers === null) {
|
156 | throw new Error("Second argument given to Cycle must be an object " + "with driver functions as properties.");
|
157 | }
|
158 | if (isObjectEmpty(drivers)) {
|
159 | throw new Error("Second argument given to Cycle must be an object " + "with at least one driver function declared as a property.");
|
160 | }
|
161 | var streamAdapter = options.streamAdapter;
|
162 | if (!streamAdapter || isObjectEmpty(streamAdapter)) {
|
163 | throw new Error("Third argument given to Cycle must be an options object " + "with the streamAdapter key supplied with a valid stream adapter.");
|
164 | }
|
165 | var sinkProxies = makeSinkProxies(drivers, streamAdapter);
|
166 | var sources = callDrivers(drivers, sinkProxies, streamAdapter);
|
167 | var sinks = main(sources);
|
168 | if (typeof window !== 'undefined') {
|
169 | window.Cyclejs = { sinks: sinks };
|
170 | }
|
171 | var run = function run() {
|
172 | var disposeReplication = replicateMany(sinks, sinkProxies, streamAdapter);
|
173 | return function () {
|
174 | disposeSources(sources);
|
175 | disposeReplication();
|
176 | };
|
177 | };
|
178 | return { sinks: sinks, sources: sources, run: run };
|
179 | }
|
180 | Object.defineProperty(exports, "__esModule", { value: true });
|
181 | exports.default = Cycle;
|
182 |
|
183 |
|
184 | },{}],3:[function(require,module,exports){
|
185 | "use strict";
|
186 | var Rx = require('rx');
|
187 | var RxJSAdapter = {
|
188 | adapt: function (originStream, originStreamSubscribe) {
|
189 | if (this.isValidStream(originStream)) {
|
190 | return originStream;
|
191 | }
|
192 | return Rx.Observable.create(function (destinationObserver) {
|
193 | var originObserver = {
|
194 | next: function (x) { return destinationObserver.onNext(x); },
|
195 | error: function (e) { return destinationObserver.onError(e); },
|
196 | complete: function () { return destinationObserver.onCompleted(); },
|
197 | };
|
198 | var dispose = originStreamSubscribe(originStream, originObserver);
|
199 | return function () {
|
200 | if (typeof dispose === 'function') {
|
201 | dispose.call(null);
|
202 | }
|
203 | };
|
204 | });
|
205 | },
|
206 | remember: function (observable) {
|
207 | return observable.shareReplay(1);
|
208 | },
|
209 | makeSubject: function () {
|
210 | var stream = new Rx.Subject();
|
211 | var observer = {
|
212 | next: function (x) { stream.onNext(x); },
|
213 | error: function (err) { stream.onError(err); },
|
214 | complete: function (x) { stream.onCompleted(); }
|
215 | };
|
216 | return { stream: stream, observer: observer };
|
217 | },
|
218 | isValidStream: function (stream) {
|
219 | return (typeof stream.subscribeOnNext === 'function' &&
|
220 | typeof stream.onValue !== 'function');
|
221 | },
|
222 | streamSubscribe: function (stream, observer) {
|
223 | var subscription = stream.subscribe(function (x) { return observer.next(x); }, function (e) { return observer.error(e); }, function (x) { return observer.complete(x); });
|
224 | return function () {
|
225 | subscription.dispose();
|
226 | };
|
227 | }
|
228 | };
|
229 | Object.defineProperty(exports, "__esModule", { value: true });
|
230 | exports.default = RxJSAdapter;
|
231 |
|
232 | },{"rx":undefined}]},{},[1])(1)
|
233 | }); |
\ | No newline at end of file |