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