UNPKG

15.1 kBJavaScriptView Raw
1import Observable from './observable'
2import Stream from './stream'
3import Property from './property'
4
5// Create a stream
6// -----------------------------------------------------------------------------
7
8// () -> Stream
9import never from './primary/never'
10
11// (number, any) -> Stream
12import later from './time-based/later'
13
14// (number, any) -> Stream
15import interval from './time-based/interval'
16
17// (number, Array<any>) -> Stream
18import sequentially from './time-based/sequentially'
19
20// (number, Function) -> Stream
21import fromPoll from './time-based/from-poll'
22
23// (number, Function) -> Stream
24import withInterval from './time-based/with-interval'
25
26// (Function) -> Stream
27import fromCallback from './primary/from-callback'
28
29// (Function) -> Stream
30import fromNodeCallback from './primary/from-node-callback'
31
32// Target = {addEventListener, removeEventListener}|{addListener, removeListener}|{on, off}
33// (Target, string, Function|undefined) -> Stream
34import fromEvents from './primary/from-events'
35
36// (Function) -> Stream
37import stream from './primary/stream'
38
39// Create a property
40// -----------------------------------------------------------------------------
41
42// (any) -> Property
43import constant from './primary/constant'
44
45// (any) -> Property
46import constantError from './primary/constant-error'
47
48// Convert observables
49// -----------------------------------------------------------------------------
50
51// (Stream|Property, Function|undefined) -> Property
52import toProperty from './one-source/to-property'
53Observable.prototype.toProperty = function(fn) {
54 return toProperty(this, fn)
55}
56
57// (Stream|Property) -> Stream
58import changes from './one-source/changes'
59Observable.prototype.changes = function() {
60 return changes(this)
61}
62
63// Interoperation with other implimentations
64// -----------------------------------------------------------------------------
65
66// (Promise) -> Property
67import fromPromise from './interop/from-promise'
68
69// (Stream|Property, Function|undefined) -> Promise
70import toPromise from './interop/to-promise'
71Observable.prototype.toPromise = function(Promise) {
72 return toPromise(this, Promise)
73}
74
75// (ESObservable) -> Stream
76import fromESObservable from './interop/from-es-observable'
77
78// (Stream|Property) -> ES7 Observable
79import toESObservable from './interop/to-es-observable'
80Observable.prototype.toESObservable = toESObservable
81import $$observable from './interop/symbol'
82Observable.prototype[$$observable] = toESObservable
83
84import * as staticLand from './interop/static-land'
85
86// Modify an observable
87// -----------------------------------------------------------------------------
88
89// (Stream, Function|undefined) -> Stream
90// (Property, Function|undefined) -> Property
91import map from './one-source/map'
92Observable.prototype.map = function(fn) {
93 return map(this, fn)
94}
95
96// (Stream, Function|undefined) -> Stream
97// (Property, Function|undefined) -> Property
98import filter from './one-source/filter'
99Observable.prototype.filter = function(fn) {
100 return filter(this, fn)
101}
102
103// (Stream, number) -> Stream
104// (Property, number) -> Property
105import take from './one-source/take'
106Observable.prototype.take = function(n) {
107 return take(this, n)
108}
109
110// (Stream, number) -> Stream
111// (Property, number) -> Property
112import takeErrors from './one-source/take-errors'
113Observable.prototype.takeErrors = function(n) {
114 return takeErrors(this, n)
115}
116
117// (Stream, Function|undefined) -> Stream
118// (Property, Function|undefined) -> Property
119import takeWhile from './one-source/take-while'
120Observable.prototype.takeWhile = function(fn) {
121 return takeWhile(this, fn)
122}
123
124// (Stream) -> Stream
125// (Property) -> Property
126import last from './one-source/last'
127Observable.prototype.last = function() {
128 return last(this)
129}
130
131// (Stream, number) -> Stream
132// (Property, number) -> Property
133import skip from './one-source/skip'
134Observable.prototype.skip = function(n) {
135 return skip(this, n)
136}
137
138// (Stream, Function|undefined) -> Stream
139// (Property, Function|undefined) -> Property
140import skipWhile from './one-source/skip-while'
141Observable.prototype.skipWhile = function(fn) {
142 return skipWhile(this, fn)
143}
144
145// (Stream, Function|undefined) -> Stream
146// (Property, Function|undefined) -> Property
147import skipDuplicates from './one-source/skip-duplicates'
148Observable.prototype.skipDuplicates = function(fn) {
149 return skipDuplicates(this, fn)
150}
151
152// (Stream, Function|falsey, any|undefined) -> Stream
153// (Property, Function|falsey, any|undefined) -> Property
154import diff from './one-source/diff'
155Observable.prototype.diff = function(fn, seed) {
156 return diff(this, fn, seed)
157}
158
159// (Stream|Property, Function, any|undefined) -> Property
160import scan from './one-source/scan'
161Observable.prototype.scan = function(fn, seed) {
162 return scan(this, fn, seed)
163}
164
165// (Stream, Function|undefined) -> Stream
166// (Property, Function|undefined) -> Property
167import flatten from './one-source/flatten'
168Observable.prototype.flatten = function(fn) {
169 return flatten(this, fn)
170}
171
172// (Stream, number) -> Stream
173// (Property, number) -> Property
174import delay from './one-source/delay'
175Observable.prototype.delay = function(wait) {
176 return delay(this, wait)
177}
178
179// Options = {leading: boolean|undefined, trailing: boolean|undefined}
180// (Stream, number, Options|undefined) -> Stream
181// (Property, number, Options|undefined) -> Property
182import throttle from './one-source/throttle'
183Observable.prototype.throttle = function(wait, options) {
184 return throttle(this, wait, options)
185}
186
187// Options = {immediate: boolean|undefined}
188// (Stream, number, Options|undefined) -> Stream
189// (Property, number, Options|undefined) -> Property
190import debounce from './one-source/debounce'
191Observable.prototype.debounce = function(wait, options) {
192 return debounce(this, wait, options)
193}
194
195// (Stream, Function|undefined) -> Stream
196// (Property, Function|undefined) -> Property
197import mapErrors from './one-source/map-errors'
198Observable.prototype.mapErrors = function(fn) {
199 return mapErrors(this, fn)
200}
201
202// (Stream, Function|undefined) -> Stream
203// (Property, Function|undefined) -> Property
204import filterErrors from './one-source/filter-errors'
205Observable.prototype.filterErrors = function(fn) {
206 return filterErrors(this, fn)
207}
208
209// (Stream) -> Stream
210// (Property) -> Property
211import ignoreValues from './one-source/ignore-values'
212Observable.prototype.ignoreValues = function() {
213 return ignoreValues(this)
214}
215
216// (Stream) -> Stream
217// (Property) -> Property
218import ignoreErrors from './one-source/ignore-errors'
219Observable.prototype.ignoreErrors = function() {
220 return ignoreErrors(this)
221}
222
223// (Stream) -> Stream
224// (Property) -> Property
225import ignoreEnd from './one-source/ignore-end'
226Observable.prototype.ignoreEnd = function() {
227 return ignoreEnd(this)
228}
229
230// (Stream, Function) -> Stream
231// (Property, Function) -> Property
232import beforeEnd from './one-source/before-end'
233Observable.prototype.beforeEnd = function(fn) {
234 return beforeEnd(this, fn)
235}
236
237// (Stream, number, number|undefined) -> Stream
238// (Property, number, number|undefined) -> Property
239import slidingWindow from './one-source/sliding-window'
240Observable.prototype.slidingWindow = function(max, min) {
241 return slidingWindow(this, max, min)
242}
243
244// Options = {flushOnEnd: boolean|undefined}
245// (Stream, Function|falsey, Options|undefined) -> Stream
246// (Property, Function|falsey, Options|undefined) -> Property
247import bufferWhile from './one-source/buffer-while'
248Observable.prototype.bufferWhile = function(fn, options) {
249 return bufferWhile(this, fn, options)
250}
251
252// (Stream, number) -> Stream
253// (Property, number) -> Property
254import bufferWithCount from './one-source/buffer-with-count'
255Observable.prototype.bufferWithCount = function(count, options) {
256 return bufferWithCount(this, count, options)
257}
258
259// Options = {flushOnEnd: boolean|undefined}
260// (Stream, number, number, Options|undefined) -> Stream
261// (Property, number, number, Options|undefined) -> Property
262import bufferWithTimeOrCount from './one-source/buffer-with-time-or-count'
263Observable.prototype.bufferWithTimeOrCount = function(wait, count, options) {
264 return bufferWithTimeOrCount(this, wait, count, options)
265}
266
267// (Stream, Function) -> Stream
268// (Property, Function) -> Property
269import transduce from './one-source/transduce'
270Observable.prototype.transduce = function(transducer) {
271 return transduce(this, transducer)
272}
273
274// (Stream, Function) -> Stream
275// (Property, Function) -> Property
276import withHandler from './one-source/with-handler'
277Observable.prototype.withHandler = function(fn) {
278 return withHandler(this, fn)
279}
280
281// (Stream, Stream -> a) -> a
282// (Property, Property -> a) -> a
283Observable.prototype.thru = function(fn) {
284 return fn(this)
285}
286
287// Combine observables
288// -----------------------------------------------------------------------------
289
290// (Array<Stream|Property>, Function|undefiend) -> Stream
291// (Array<Stream|Property>, Array<Stream|Property>, Function|undefiend) -> Stream
292import combine from './many-sources/combine'
293Observable.prototype.combine = function(other, combinator) {
294 return combine([this, other], combinator)
295}
296
297// (Array<Stream|Property>, Function|undefiend) -> Stream
298import zip from './many-sources/zip'
299Observable.prototype.zip = function(other, combinator) {
300 return zip([this, other], combinator)
301}
302
303// (Array<Stream|Property>) -> Stream
304import merge from './many-sources/merge'
305Observable.prototype.merge = function(other) {
306 return merge([this, other])
307}
308
309// (Array<Stream|Property>) -> Stream
310import concat from './many-sources/concat'
311Observable.prototype.concat = function(other) {
312 return concat([this, other])
313}
314
315// () -> Pool
316import Pool from './many-sources/pool'
317const pool = function() {
318 return new Pool()
319}
320
321// (Function) -> Stream
322import repeat from './many-sources/repeat'
323
324// Options = {concurLim: number|undefined, queueLim: number|undefined, drop: 'old'|'new'|undefiend}
325// (Stream|Property, Function|falsey, Options|undefined) -> Stream
326import FlatMap from './many-sources/flat-map'
327Observable.prototype.flatMap = function(fn) {
328 return new FlatMap(this, fn).setName(this, 'flatMap')
329}
330Observable.prototype.flatMapLatest = function(fn) {
331 return new FlatMap(this, fn, {concurLim: 1, drop: 'old'}).setName(this, 'flatMapLatest')
332}
333Observable.prototype.flatMapFirst = function(fn) {
334 return new FlatMap(this, fn, {concurLim: 1}).setName(this, 'flatMapFirst')
335}
336Observable.prototype.flatMapConcat = function(fn) {
337 return new FlatMap(this, fn, {queueLim: -1, concurLim: 1}).setName(this, 'flatMapConcat')
338}
339Observable.prototype.flatMapConcurLimit = function(fn, limit) {
340 return new FlatMap(this, fn, {queueLim: -1, concurLim: limit}).setName(this, 'flatMapConcurLimit')
341}
342
343// (Stream|Property, Function|falsey) -> Stream
344import FlatMapErrors from './many-sources/flat-map-errors'
345Observable.prototype.flatMapErrors = function(fn) {
346 return new FlatMapErrors(this, fn).setName(this, 'flatMapErrors')
347}
348
349// Combine two observables
350// -----------------------------------------------------------------------------
351
352// (Stream, Stream|Property) -> Stream
353// (Property, Stream|Property) -> Property
354import filterBy from './two-sources/filter-by'
355Observable.prototype.filterBy = function(other) {
356 return filterBy(this, other)
357}
358
359// (Stream, Stream|Property, Function|undefiend) -> Stream
360// (Property, Stream|Property, Function|undefiend) -> Property
361import sampledBy2items from './two-sources/sampled-by'
362Observable.prototype.sampledBy = function(other, combinator) {
363 return sampledBy2items(this, other, combinator)
364}
365
366// (Stream, Stream|Property) -> Stream
367// (Property, Stream|Property) -> Property
368import skipUntilBy from './two-sources/skip-until-by'
369Observable.prototype.skipUntilBy = function(other) {
370 return skipUntilBy(this, other)
371}
372
373// (Stream, Stream|Property) -> Stream
374// (Property, Stream|Property) -> Property
375import takeUntilBy from './two-sources/take-until-by'
376Observable.prototype.takeUntilBy = function(other) {
377 return takeUntilBy(this, other)
378}
379
380// Options = {flushOnEnd: boolean|undefined}
381// (Stream, Stream|Property, Options|undefined) -> Stream
382// (Property, Stream|Property, Options|undefined) -> Property
383import bufferBy from './two-sources/buffer-by'
384Observable.prototype.bufferBy = function(other, options) {
385 return bufferBy(this, other, options)
386}
387
388// Options = {flushOnEnd: boolean|undefined}
389// (Stream, Stream|Property, Options|undefined) -> Stream
390// (Property, Stream|Property, Options|undefined) -> Property
391import bufferWhileBy from './two-sources/buffer-while-by'
392Observable.prototype.bufferWhileBy = function(other, options) {
393 return bufferWhileBy(this, other, options)
394}
395
396// Deprecated
397// -----------------------------------------------------------------------------
398
399let DEPRECATION_WARNINGS = true
400export function dissableDeprecationWarnings() {
401 DEPRECATION_WARNINGS = false
402}
403
404function warn(msg) {
405 if (DEPRECATION_WARNINGS && console && typeof console.warn === 'function') {
406 const msg2 = '\nHere is an Error object for you containing the call stack:'
407 console.warn(msg, msg2, new Error())
408 }
409}
410
411// (Stream|Property, Stream|Property) -> Property
412import awaiting from './two-sources/awaiting'
413Observable.prototype.awaiting = function(other) {
414 warn('You are using deprecated .awaiting() method, see https://github.com/kefirjs/kefir/issues/145')
415 return awaiting(this, other)
416}
417
418// (Stream, Function|undefined) -> Stream
419// (Property, Function|undefined) -> Property
420import valuesToErrors from './one-source/values-to-errors'
421Observable.prototype.valuesToErrors = function(fn) {
422 warn('You are using deprecated .valuesToErrors() method, see https://github.com/kefirjs/kefir/issues/149')
423 return valuesToErrors(this, fn)
424}
425
426// (Stream, Function|undefined) -> Stream
427// (Property, Function|undefined) -> Property
428import errorsToValues from './one-source/errors-to-values'
429Observable.prototype.errorsToValues = function(fn) {
430 warn('You are using deprecated .errorsToValues() method, see https://github.com/kefirjs/kefir/issues/149')
431 return errorsToValues(this, fn)
432}
433
434// (Stream) -> Stream
435// (Property) -> Property
436import endOnError from './one-source/end-on-error'
437Observable.prototype.endOnError = function() {
438 warn('You are using deprecated .endOnError() method, see https://github.com/kefirjs/kefir/issues/150')
439 return endOnError(this)
440}
441
442// Exports
443// --------------------------------------------------------------------------
444
445const Kefir = {
446 Observable,
447 Stream,
448 Property,
449 never,
450 later,
451 interval,
452 sequentially,
453 fromPoll,
454 withInterval,
455 fromCallback,
456 fromNodeCallback,
457 fromEvents,
458 stream,
459 constant,
460 constantError,
461 fromPromise,
462 fromESObservable,
463 combine,
464 zip,
465 merge,
466 concat,
467 Pool,
468 pool,
469 repeat,
470 staticLand,
471}
472
473Kefir.Kefir = Kefir
474
475export {
476 Kefir,
477 Observable,
478 Stream,
479 Property,
480 never,
481 later,
482 interval,
483 sequentially,
484 fromPoll,
485 withInterval,
486 fromCallback,
487 fromNodeCallback,
488 fromEvents,
489 stream,
490 constant,
491 constantError,
492 fromPromise,
493 fromESObservable,
494 combine,
495 zip,
496 merge,
497 concat,
498 Pool,
499 pool,
500 repeat,
501 staticLand,
502}
503
504export default Kefir