@ts-livedata/core
TypeScript icon, indicating that this package has built-in type declarations

1.0.1-alpha01 • Public • Published

TS LiveData Library

npm version CircleCI

About

Observer pattern based library for TypeScript, similar to Android's LiveData.

For information on the Observer pattern please visit Wikipedia.

Installation

npm install @ts-livedata/core
yarn add @ts-livedata/core

Usage

import {MutableLiveData, Observer} from "@ts-livedata/core"

const liveData = new MutableLiveData<String | null>()

const observer: Observer<String | null> = (value => {
    if (value) {
        console.log(`your value: ${value}`)
    } else {
        console.log(`null value`)
    }
})

// Can observer before or after posting a value
liveData.observe(observer)

liveData.postValue("TypeScript LiveData")

// When you're ready to stop listening for changes
liveData.removeObserver(observer)

// Or you can remove all observers via
liveData.removeAllObservers()

Questions

Feel free to drop a Github issue with any questions you may have.

License

This project is licensed under the terms of the Apache 2.0 license.

Package Sidebar

Install

npm i @ts-livedata/core

Weekly Downloads

1

Version

1.0.1-alpha01

License

Apache-2.0

Unpacked Size

9.01 kB

Total Files

11

Last publish

Collaborators

  • brendangoldberg