import * as O from "baconjs" ; import * as A from "./atom" ; import * as L from "./lens" ; import { getCurrentValue } from "./currentvalue" ; import { endEvent } from "baconjs/types/event" ; export type NativeProperty < T > = O . Property < T > ; export type NativeAtom < T > = A . Atom < T > ; export type NativeEventStream < T > = O . EventStream < T > ; export type Lens < A , B > = L . Lens < A , B > ; export type Scope = { start ( ) : void ; end ( ) : void ; } ; const mockScope = { start ( ) { } , end ( ) { } , } ; export function createScope ( ) { return mockScope ; } export function mkScope ( scopeFn ) { return mockScope ; } export type Predicate < A > = ( value : A ) => boolean ; export type Observable < T > = { } ; export type Atom < T > = { } ; export type Property < T > = { } ; export type EventStream < T > = { } ; export interface Bus < T > extends NativeEventStream < T > { } export type Unsub = ( ) => void ; export function bus < T > ( ) { return new O . Bus ( ) ; } export function pushAndEnd < T > ( bus , value ) { const nativeBus = bus as O . Bus < T > ; nativeBus . push ( value ) ; nativeBus . end ( ) ; } export function get < A > ( prop ) { return getCurrentValue ( prop as O . Property < A > ) ; } export function set < A > ( atom , value ) { ; ( atom as A . Atom < A > ) . set ( value ) ; } export function isAtom ( x ) { return A . isAtom ( x ) ; } export function isProperty ( x ) { return x instanceof O . Property ; } export function forEach < V > ( x , fn ) { return ( x as O . Observable < any > ) . forEach ( fn ) ; } export function view < A , K extends keyof A > ( a , key ) ; export function view < A , K extends keyof A > ( a , key ) ; export function view < A , B > ( a , fn ) ; export function view < A , K extends keyof A > ( a , key ) { if ( typeof key === "function" ) { return a . map ( key ) . skipDuplicates ( ) ; } else if ( A . isAtom ( a ) ) { return a . view ( key as any ) ; } else if ( a instanceof O . Property ) { if ( L . isLens ( key ) ) { return a . map ( key . get ) . skipDuplicates ( ) ; } return a . map ( ( x ) => x [ key ] ) . skipDuplicates ( ) ; } else { throw Error ( "Unknown observable: " + a ) ; } } export function filter < A > ( a , fn , scope ) ; export function filter < A > ( a , fn , scope ) ; export function filter < A > ( a , fn , scope ) { if ( A . isAtom ( a ) ) { return a . freezeUnless ( fn as any ) ; } else if ( a instanceof O . Property ) { return a . filter ( fn ) ; } else { throw Error ( "Unknown observable: " + a ) ; } } export const observablesImplementationName = "Bacon.js" ;