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 |
|
3 | var process = module.exports = {};
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var cachedSetTimeout;
|
11 | var cachedClearTimeout;
|
12 |
|
13 | function defaultSetTimout() {
|
14 | throw new Error('setTimeout has not been defined');
|
15 | }
|
16 | function defaultClearTimeout () {
|
17 | throw new Error('clearTimeout has not been defined');
|
18 | }
|
19 | (function () {
|
20 | try {
|
21 | if (typeof setTimeout === 'function') {
|
22 | cachedSetTimeout = setTimeout;
|
23 | } else {
|
24 | cachedSetTimeout = defaultSetTimout;
|
25 | }
|
26 | } catch (e) {
|
27 | cachedSetTimeout = defaultSetTimout;
|
28 | }
|
29 | try {
|
30 | if (typeof clearTimeout === 'function') {
|
31 | cachedClearTimeout = clearTimeout;
|
32 | } else {
|
33 | cachedClearTimeout = defaultClearTimeout;
|
34 | }
|
35 | } catch (e) {
|
36 | cachedClearTimeout = defaultClearTimeout;
|
37 | }
|
38 | } ())
|
39 | function runTimeout(fun) {
|
40 | if (cachedSetTimeout === setTimeout) {
|
41 |
|
42 | return setTimeout(fun, 0);
|
43 | }
|
44 |
|
45 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
46 | cachedSetTimeout = setTimeout;
|
47 | return setTimeout(fun, 0);
|
48 | }
|
49 | try {
|
50 |
|
51 | return cachedSetTimeout(fun, 0);
|
52 | } catch(e){
|
53 | try {
|
54 |
|
55 | return cachedSetTimeout.call(null, fun, 0);
|
56 | } catch(e){
|
57 |
|
58 | return cachedSetTimeout.call(this, fun, 0);
|
59 | }
|
60 | }
|
61 |
|
62 |
|
63 | }
|
64 | function runClearTimeout(marker) {
|
65 | if (cachedClearTimeout === clearTimeout) {
|
66 |
|
67 | return clearTimeout(marker);
|
68 | }
|
69 |
|
70 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
71 | cachedClearTimeout = clearTimeout;
|
72 | return clearTimeout(marker);
|
73 | }
|
74 | try {
|
75 |
|
76 | return cachedClearTimeout(marker);
|
77 | } catch (e){
|
78 | try {
|
79 |
|
80 | return cachedClearTimeout.call(null, marker);
|
81 | } catch (e){
|
82 |
|
83 |
|
84 | return cachedClearTimeout.call(this, marker);
|
85 | }
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 | }
|
91 | var queue = [];
|
92 | var draining = false;
|
93 | var currentQueue;
|
94 | var queueIndex = -1;
|
95 |
|
96 | function cleanUpNextTick() {
|
97 | if (!draining || !currentQueue) {
|
98 | return;
|
99 | }
|
100 | draining = false;
|
101 | if (currentQueue.length) {
|
102 | queue = currentQueue.concat(queue);
|
103 | } else {
|
104 | queueIndex = -1;
|
105 | }
|
106 | if (queue.length) {
|
107 | drainQueue();
|
108 | }
|
109 | }
|
110 |
|
111 | function drainQueue() {
|
112 | if (draining) {
|
113 | return;
|
114 | }
|
115 | var timeout = runTimeout(cleanUpNextTick);
|
116 | draining = true;
|
117 |
|
118 | var len = queue.length;
|
119 | while(len) {
|
120 | currentQueue = queue;
|
121 | queue = [];
|
122 | while (++queueIndex < len) {
|
123 | if (currentQueue) {
|
124 | currentQueue[queueIndex].run();
|
125 | }
|
126 | }
|
127 | queueIndex = -1;
|
128 | len = queue.length;
|
129 | }
|
130 | currentQueue = null;
|
131 | draining = false;
|
132 | runClearTimeout(timeout);
|
133 | }
|
134 |
|
135 | process.nextTick = function (fun) {
|
136 | var args = new Array(arguments.length - 1);
|
137 | if (arguments.length > 1) {
|
138 | for (var i = 1; i < arguments.length; i++) {
|
139 | args[i - 1] = arguments[i];
|
140 | }
|
141 | }
|
142 | queue.push(new Item(fun, args));
|
143 | if (queue.length === 1 && !draining) {
|
144 | runTimeout(drainQueue);
|
145 | }
|
146 | };
|
147 |
|
148 |
|
149 | function Item(fun, array) {
|
150 | this.fun = fun;
|
151 | this.array = array;
|
152 | }
|
153 | Item.prototype.run = function () {
|
154 | this.fun.apply(null, this.array);
|
155 | };
|
156 | process.title = 'browser';
|
157 | process.browser = true;
|
158 | process.env = {};
|
159 | process.argv = [];
|
160 | process.version = '';
|
161 | process.versions = {};
|
162 |
|
163 | function noop() {}
|
164 |
|
165 | process.on = noop;
|
166 | process.addListener = noop;
|
167 | process.once = noop;
|
168 | process.off = noop;
|
169 | process.removeListener = noop;
|
170 | process.removeAllListeners = noop;
|
171 | process.emit = noop;
|
172 |
|
173 | process.binding = function (name) {
|
174 | throw new Error('process.binding is not supported');
|
175 | };
|
176 |
|
177 | process.cwd = function () { return '/' };
|
178 | process.chdir = function (dir) {
|
179 | throw new Error('process.chdir is not supported');
|
180 | };
|
181 | process.umask = function() { return 0; };
|
182 |
|
183 | },{}],2:[function(require,module,exports){
|
184 | (function (global){
|
185 | "use strict";
|
186 | Object.defineProperty(exports, "__esModule", { value: true });
|
187 | function getGlobal() {
|
188 | var globalObj;
|
189 | if (typeof window !== 'undefined') {
|
190 | globalObj = window;
|
191 | }
|
192 | else if (typeof global !== 'undefined') {
|
193 | globalObj = global;
|
194 | }
|
195 | else {
|
196 | globalObj = this;
|
197 | }
|
198 | globalObj.Cyclejs = globalObj.Cyclejs || {};
|
199 | globalObj = globalObj.Cyclejs;
|
200 | globalObj.adaptStream = globalObj.adaptStream || (function (x) { return x; });
|
201 | return globalObj;
|
202 | }
|
203 | function setAdapt(f) {
|
204 | getGlobal().adaptStream = f;
|
205 | }
|
206 | exports.setAdapt = setAdapt;
|
207 | function adapt(stream) {
|
208 | return getGlobal().adaptStream(stream);
|
209 | }
|
210 | exports.adapt = adapt;
|
211 |
|
212 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
213 | },{}],3:[function(require,module,exports){
|
214 | (function (global){
|
215 | "use strict";
|
216 | Object.defineProperty(exports, "__esModule", { value: true });
|
217 | var xstream_1 = (typeof window !== "undefined" ? window['xstream'] : typeof global !== "undefined" ? global['xstream'] : null);
|
218 | var adapt_1 = require("./adapt");
|
219 | var quicktask_1 = require("quicktask");
|
220 | var scheduleMicrotask = quicktask_1.default();
|
221 | function makeSinkProxies(drivers) {
|
222 | var sinkProxies = {};
|
223 | for (var name_1 in drivers) {
|
224 | if (drivers.hasOwnProperty(name_1)) {
|
225 | sinkProxies[name_1] = xstream_1.default.create();
|
226 | }
|
227 | }
|
228 | return sinkProxies;
|
229 | }
|
230 | function callDrivers(drivers, sinkProxies) {
|
231 | var sources = {};
|
232 | for (var name_2 in drivers) {
|
233 | if (drivers.hasOwnProperty(name_2)) {
|
234 | sources[name_2] = drivers[name_2](sinkProxies[name_2], name_2);
|
235 | if (sources[name_2] && typeof sources[name_2] === 'object') {
|
236 | sources[name_2]._isCycleSource = name_2;
|
237 | }
|
238 | }
|
239 | }
|
240 | return sources;
|
241 | }
|
242 |
|
243 | function adaptSources(sources) {
|
244 | for (var name_3 in sources) {
|
245 | if (sources.hasOwnProperty(name_3) &&
|
246 | sources[name_3] &&
|
247 | typeof sources[name_3]['shamefullySendNext'] === 'function') {
|
248 | sources[name_3] = adapt_1.adapt(sources[name_3]);
|
249 | }
|
250 | }
|
251 | return sources;
|
252 | }
|
253 | function replicateMany(sinks, sinkProxies) {
|
254 | var sinkNames = Object.keys(sinks).filter(function (name) { return !!sinkProxies[name]; });
|
255 | var buffers = {};
|
256 | var replicators = {};
|
257 | sinkNames.forEach(function (name) {
|
258 | buffers[name] = { _n: [], _e: [] };
|
259 | replicators[name] = {
|
260 | next: function (x) { return buffers[name]._n.push(x); },
|
261 | error: function (err) { return buffers[name]._e.push(err); },
|
262 | complete: function () { },
|
263 | };
|
264 | });
|
265 | var subscriptions = sinkNames.map(function (name) {
|
266 | return xstream_1.default.fromObservable(sinks[name]).subscribe(replicators[name]);
|
267 | });
|
268 | sinkNames.forEach(function (name) {
|
269 | var listener = sinkProxies[name];
|
270 | var next = function (x) {
|
271 | scheduleMicrotask(function () { return listener._n(x); });
|
272 | };
|
273 | var error = function (err) {
|
274 | scheduleMicrotask(function () {
|
275 | (console.error || console.log)(err);
|
276 | listener._e(err);
|
277 | });
|
278 | };
|
279 | buffers[name]._n.forEach(next);
|
280 | buffers[name]._e.forEach(error);
|
281 | replicators[name].next = next;
|
282 | replicators[name].error = error;
|
283 |
|
284 |
|
285 | replicators[name]._n = next;
|
286 | replicators[name]._e = error;
|
287 | });
|
288 | buffers = null;
|
289 | return function disposeReplication() {
|
290 | subscriptions.forEach(function (s) { return s.unsubscribe(); });
|
291 | sinkNames.forEach(function (name) { return sinkProxies[name]._c(); });
|
292 | };
|
293 | }
|
294 | function disposeSources(sources) {
|
295 | for (var k in sources) {
|
296 | if (sources.hasOwnProperty(k) &&
|
297 | sources[k] &&
|
298 | sources[k].dispose) {
|
299 | sources[k].dispose();
|
300 | }
|
301 | }
|
302 | }
|
303 | function isObjectEmpty(obj) {
|
304 | return Object.keys(obj).length === 0;
|
305 | }
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | function setup(main, drivers) {
|
335 | if (typeof main !== "function") {
|
336 | throw new Error("First argument given to Cycle must be the 'main' " + "function.");
|
337 | }
|
338 | if (typeof drivers !== "object" || drivers === null) {
|
339 | throw new Error("Second argument given to Cycle must be an object " +
|
340 | "with driver functions as properties.");
|
341 | }
|
342 | if (isObjectEmpty(drivers)) {
|
343 | throw new Error("Second argument given to Cycle must be an object " +
|
344 | "with at least one driver function declared as a property.");
|
345 | }
|
346 | var sinkProxies = makeSinkProxies(drivers);
|
347 | var sources = callDrivers(drivers, sinkProxies);
|
348 | var adaptedSources = adaptSources(sources);
|
349 | var sinks = main(adaptedSources);
|
350 | if (typeof window !== 'undefined') {
|
351 | window.Cyclejs = window.Cyclejs || {};
|
352 | window.Cyclejs.sinks = sinks;
|
353 | }
|
354 | function _run() {
|
355 | var disposeReplication = replicateMany(sinks, sinkProxies);
|
356 | return function dispose() {
|
357 | disposeSources(sources);
|
358 | disposeReplication();
|
359 | };
|
360 | }
|
361 | return { sinks: sinks, sources: sources, run: _run };
|
362 | }
|
363 | exports.setup = setup;
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 | function run(main, drivers) {
|
392 | var program = setup(main, drivers);
|
393 | if (typeof window !== 'undefined' &&
|
394 | window['CyclejsDevTool_startGraphSerializer']) {
|
395 | window['CyclejsDevTool_startGraphSerializer'](program.sinks);
|
396 | }
|
397 | return program.run();
|
398 | }
|
399 | exports.run = run;
|
400 | exports.default = run;
|
401 |
|
402 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
403 | },{"./adapt":2,"quicktask":4}],4:[function(require,module,exports){
|
404 | (function (process){
|
405 | "use strict";
|
406 | Object.defineProperty(exports, "__esModule", { value: true });
|
407 | function microtask() {
|
408 | if (typeof MutationObserver !== 'undefined') {
|
409 | var node_1 = document.createTextNode('');
|
410 | var queue_1 = [];
|
411 | var i_1 = 0;
|
412 | new MutationObserver(function () {
|
413 | while (queue_1.length) {
|
414 | queue_1.shift()();
|
415 | }
|
416 | }).observe(node_1, { characterData: true });
|
417 | return function (fn) {
|
418 | queue_1.push(fn);
|
419 | node_1.data = i_1 = 1 - i_1;
|
420 | };
|
421 | }
|
422 | else if (typeof setImmediate !== 'undefined') {
|
423 | return setImmediate;
|
424 | }
|
425 | else if (typeof process !== 'undefined') {
|
426 | return process.nextTick;
|
427 | }
|
428 | else {
|
429 | return setTimeout;
|
430 | }
|
431 | }
|
432 | exports.default = microtask;
|
433 |
|
434 | }).call(this,require('_process'))
|
435 | },{"_process":1}]},{},[3])(3)
|
436 | }); |
\ | No newline at end of file |