Options
Menu

Class BoolUnit

BoolUnit is a reactive storage Unit that stores boolean value.

It only accepts boolean data type as its value. It ensures that at any point of time the value would always be boolean.

Learn more about Units here.
Learn more about BoolUnit here.

Just like every other ActiveJS Unit:

  • BoolUnit extends UnitBase
  • Which further extends Base and Observable

Hierarchy

Constructors

constructor

Properties

Readonly cacheSize

cacheSize: number

Size of the cache, dictating how many values can be cached at a given time.

default

2

minimum

1

maximum

Infinity

Readonly config

config: Readonly<UnitConfig<boolean>>

Configured options. Combination of global-options GlobalUnitConfig and the options passed on instantiation.

Readonly events$

events$: Observable<UnitEvents<boolean>>

On-demand observable events.

Readonly future$

future$: Observable<boolean> = this.futureSubject.asObservable()

An Observable to observe future values, unlike the default Observable it doesn't replay when subscribed to, rather it waits for the next value.

Accessors

cacheIndex

  • get cacheIndex(): number

cachedValuesCount

  • get cachedValuesCount(): number

emitCount

  • get emitCount(): number

isEmpty

  • get isEmpty(): boolean

isFrozen

  • get isFrozen(): boolean

isMuted

  • get isMuted(): boolean

Access Value Methods

cachedValues

  • cachedValues(): boolean[]

initialValue

  • initialValue(): boolean

rawValue

  • rawValue(): boolean
  • If the Unit has a non-primitive value, use it to get access to the current value, without creating a deep-copy.

    This can come in handy if the Unit is configured to be immutable, and you want to perform a non-mutating action without creating a deep-copy of the value.

    Returns boolean

value

  • value(): boolean

Cache Navigation Methods

goBack

  • goBack(): boolean

goForward

  • goForward(): boolean
  • After going back in the cache (ie: re-emitting an old value from the cache),
    use this method to go to the next value, without creating a new entry in the cache.

    It can be used as Redo.

    It doesn't work if the Unit is frozen isFrozen. It only works if the current value is not the last value in the cache.
    ie: the cacheIndex is not equal to cachedValuesCount - 1

    triggers

    EventUnitJump

    Returns boolean

    true if the cache-navigation was successful, otherwise false

jump

  • jump(steps: number): boolean
  • Use this method to re-emit a value from the cache, by jumping specific steps backwards or forwards,
    without creating a new entry in the cache.

    It doesn't work if the Unit is frozen isFrozen or steps is not a number. It only works if the new calculated index is in the bounds of cachedValues,
    ie: the new-index is >= 0, and less than cachedValuesCount, but
    not equal to current cacheIndex.

    triggers

    EventUnitJump

    Parameters

    • steps: number

      Number of steps to jump in the cache, negative to jump backwards, positive to jump forwards

    Returns boolean

    true if the cache-navigation was successful, otherwise false.

jumpToEnd

  • jumpToEnd(): boolean

jumpToStart

  • jumpToStart(): boolean

Common Methods

asObservable

  • asObservable(): Observable<boolean>
  • Creates a new Observable using the default Observable as source. Use this to conceal other aspects of a Unit, System, Action or Cluster except the Observable part.

    Returns Observable<boolean>

    An Observable with the value of a Unit, System, Action or Cluster.

createStream

  • A helper method that creates a stream by subscribing to the Observable returned by the param observableProducer callback.

    Ideally the callback function creates an Observable by applying Observable.pipe.

    Just know that you should catch the error in a sub-pipe (ie: do not let it propagate to the main-pipe), otherwise as usual the stream will stop working, and will not react on any further emissions.

    Type parameters

    • R

    Parameters

    Returns Stream

replay

  • replay(): boolean

toJsonString

  • toJsonString(): string

Common Action/Units Methods

dispatch

  • Method to dispatch new value by passing the value directly, or
    by passing a value-producer-function that produces the value using the current value.

    Given a value, it either gets dispatched if it's allowed by wouldDispatch,
    or it gets ignored if not allowed.

    If the Unit is not configured to be immutable, then
    the value-producer-function (param valueOrProducer) should not mutate the current value,
    which is provided as an argument to the function.

    If you mutate the value, then the cached-value might also get mutated,
    as the cached-value is saved by reference, which can result in unpredictable state.

    triggers

    EventUnitDispatch, or EventUnitDispatchFail, depending on the success of dispatch.

    Parameters

    Returns boolean | undefined

    true if value got dispatched, otherwise false. If UnitConfig.dispatchDebounce is enabled, then it'll return undefined.

  • Method to dispatch new value by passing the value directly, or
    by passing a value-producer-function that produces the value using the current value.

    Given a value, it either gets dispatched if it's allowed by wouldDispatch,
    or it gets ignored if not allowed.

    If the Unit is not configured to be immutable, then
    the value-producer-function (param valueOrProducer) should not mutate the current value,
    which is provided as an argument to the function.

    If you mutate the value, then the cached-value might also get mutated,
    as the cached-value is saved by reference, which can result in unpredictable state.

    triggers

    EventUnitDispatch, or EventUnitDispatchFail, depending on the success of dispatch.

    Parameters

    Returns boolean | undefined

    true if value got dispatched, otherwise false. If UnitConfig.dispatchDebounce is enabled, then it'll return undefined.

Common Units Methods

clear

clearCache

  • Clears the cached values, current value stays intact, but it gets removed from the cache.
    Meaning, if you dispatch a new value you can't goBack.
    To keep the last value in the cache, pass {leaveLast: true} in the param options.

    It only works if the Unit is not frozen and there's something left to clear after evaluating the param options.

    Similar to preserving the last value, you can preserve the first value by passing {leaveFirst: true}. Or preserve both first and last value by passing both options together.

    triggers

    EventUnitClearCache

    Parameters

    Returns boolean

    true if the cache was cleared, otherwise false

clearPersistedValue

  • clearPersistedValue(): boolean

clearValue

  • clearValue(): boolean

freeze

  • freeze(): void

getCachedValue

  • getCachedValue(index: number): boolean | undefined

mute

  • mute(): void
  • Mute the Unit, to stop emitting values as well as events, so that the subscribers are not triggered.
    All other functionalities stay unaffected. ie: cache it still updated, value is still updated.

    Note: If you subscribe to the default Observable while the Unit is muted,
    it will replay the last value emitted before muting the Unit,
    because new values are not being emitted.

    Returns void

reset

resetValue

  • resetValue(): boolean

unfreeze

  • unfreeze(): void

unmute

  • unmute(): void
  • Unmute the Unit, to resume emitting values, and events.
    If a value was dispatched while the Unit was muted, the most recent value immediately gets emitted,
    so that subscribers can be in sync again.
    However, other events$ are lost, and they will only emit on the next event.

    It only works if the Unit is muted.
    Moreover, it works even if the Unit is frozen,
    but no value will be emitted because no values would have been dispatched while the Unit was frozen.

    triggers

    EventUnitUnmute

    Returns void

wouldDispatch

  • wouldDispatch(value: boolean, force?: boolean): boolean

Other Methods

pipe

  • pipe(): Observable<boolean>
  • pipe<A>(op1: OperatorFunction<boolean, A>): Observable<A>
  • pipe<A, B>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>): Observable<B>
  • pipe<A, B, C>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Observable<C>
  • pipe<A, B, C, D>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Observable<D>
  • pipe<A, B, C, D, E>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Observable<E>
  • pipe<A, B, C, D, E, F>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>): Observable<F>
  • pipe<A, B, C, D, E, F, G>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): Observable<G>
  • pipe<A, B, C, D, E, F, G, H>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): Observable<H>
  • pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Observable<I>
  • pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<boolean, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<{}>
  • Returns Observable<boolean>

  • Type parameters

    • A

    Parameters

    • op1: OperatorFunction<boolean, A>

    Returns Observable<A>

  • Type parameters

    • A

    • B

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>

    Returns Observable<B>

  • Type parameters

    • A

    • B

    • C

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>

    Returns Observable<C>

  • Type parameters

    • A

    • B

    • C

    • D

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>

    Returns Observable<D>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>

    Returns Observable<E>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>
    • op6: OperatorFunction<E, F>

    Returns Observable<F>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>
    • op6: OperatorFunction<E, F>
    • op7: OperatorFunction<F, G>

    Returns Observable<G>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>
    • op6: OperatorFunction<E, F>
    • op7: OperatorFunction<F, G>
    • op8: OperatorFunction<G, H>

    Returns Observable<H>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>
    • op6: OperatorFunction<E, F>
    • op7: OperatorFunction<F, G>
    • op8: OperatorFunction<G, H>
    • op9: OperatorFunction<H, I>

    Returns Observable<I>

  • Type parameters

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    Parameters

    • op1: OperatorFunction<boolean, A>
    • op2: OperatorFunction<A, B>
    • op3: OperatorFunction<B, C>
    • op4: OperatorFunction<C, D>
    • op5: OperatorFunction<D, E>
    • op6: OperatorFunction<E, F>
    • op7: OperatorFunction<F, G>
    • op8: OperatorFunction<G, H>
    • op9: OperatorFunction<H, I>
    • Rest ...operations: OperatorFunction<any, any>[]

    Returns Observable<{}>

subscribe

  • subscribe(observer?: PartialObserver<boolean>): Subscription
  • subscribe(next: null | undefined, error: null | undefined, complete: () => void): Subscription
  • subscribe(next: null | undefined, error: (error: any) => void, complete?: () => void): Subscription
  • subscribe(next: (value: boolean) => void, error: null | undefined, complete: () => void): Subscription
  • subscribe(next?: (value: boolean) => void, error?: (error: any) => void, complete?: () => void): Subscription
  • Parameters

    • Optional observer: PartialObserver<boolean>

    Returns Subscription

  • deprecated

    Use an observer instead of a complete callback

    Parameters

    • next: null | undefined
    • error: null | undefined
    • complete: () => void
        • (): void
        • Returns void

    Returns Subscription

  • deprecated

    Use an observer instead of an error callback

    Parameters

    • next: null | undefined
    • error: (error: any) => void
        • (error: any): void
        • Parameters

          • error: any

          Returns void

    • Optional complete: () => void
        • (): void
        • Returns void

    Returns Subscription

  • deprecated

    Use an observer instead of a complete callback

    Parameters

    • next: (value: boolean) => void
        • (value: boolean): void
        • Parameters

          • value: boolean

          Returns void

    • error: null | undefined
    • complete: () => void
        • (): void
        • Returns void

    Returns Subscription

  • Parameters

    • Optional next: (value: boolean) => void
        • (value: boolean): void
        • Parameters

          • value: boolean

          Returns void

    • Optional error: (error: any) => void
        • (error: any): void
        • Parameters

          • error: any

          Returns void

    • Optional complete: () => void
        • (): void
        • Returns void

    Returns Subscription

toPromise

  • toPromise<T>(this: Observable<T>): Promise<T>
  • toPromise<T>(this: Observable<T>, PromiseCtor: typeof Promise): Promise<T>
  • toPromise<T>(this: Observable<T>, PromiseCtor: PromiseConstructorLike): Promise<T>
  • Type parameters

    • T

    Parameters

    • this: Observable<T>

    Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • this: Observable<T>
    • PromiseCtor: typeof Promise

    Returns Promise<T>

  • Type parameters

    • T

    Parameters

    • this: Observable<T>
    • PromiseCtor: PromiseConstructorLike

    Returns Promise<T>