LiveData.js

LiveData.js is a lightweight observable data holder class inspired from Google Android Jetpack library


flash_on

Speeds up development

We did most of the heavy lifting for you to provide a default stylings that incorporate our custom components. Additionally, we refined animations and transitions to provide a smoother experience for developers.

compress

Lightweight Size

By utilizing elements and principles of Material Design, we were able to create a framework that incorporates components and animations that provide more feedback to users. Additionally, a single underlying responsive system across all platforms allow for a more unified user experience.

settings

Easy to work with

We have provided detailed documentation as well as specific code examples to help new users get started. We are also always open to feedback and can answer any questions a user may have about Materialize.



Import via CDN

Creates a new instance of the LiveData class


<script src="https://unpkg.com/js-livedata@1.0.2/livedata.min.js"></script>

                            
Declaration

Creates a new instance of the LiveData class


    const data = new LiveData()

                            
Observing a LiveData

Getting instant callback whenever the value are changed


    data.observe(v => {
        console.log('observe', v)
    })

                            
Debounced observe

Observing changes in the data object with a debounce mechanism


    data.observeDebounce(v => {
        console.log('observeDebounce', v)
    })

                            

or with your prefered time


    data.observeDebounce(v => {
        console.log('observeDebounce', v)
    }, 1300)

                            
Throttled observe

Observing changes in the data object with a throttled mechanism


    data.observeThrottle(v => {
        console.log('observeThrottle', v)
    })

                            

or with your prefered time


    data.observeThrottle(v => {
        console.log('observeThrottle', v)
    }, 1300)

                            
Post a value

Posts an asynchronous task to a main thread to set the given value.


    data.postValue('Hello World!')

                            
Input binding

You can just post value from an element event


    <input type="text" oninput="data.postValue(this.value)" />

                            
Input binding demo
Output:

Hello World!

Debounced observe
LiveValidator

Creates a new instance of the LiveValidator class


    const validator = new LiveValidator()
    // or with defined keys
    const validator = new LiveValidator(['username', 'password'])

                            
Observing a LiveValidator

Getting instant callback whenever the form are valid


    validator.observe((validity, map) => {
        console.log('validator', validity, map)
    })

                            
Set a key validity

    validator.set('username', someValue != '' && someValue.length >= 8)

                            
Input binding

You can just set validity from an element event with the key


    <input type="text" oninput="validator.set('username', this.value != '')" />

                            
LiveValidator demo
account_circle Min 8 chars
key

Is it valid?

Form validity value will be here