An open API service indexing awesome lists of open source software.

https://github.com/portomartin/npmMutableLiveData

Java like LiveData pattern
https://github.com/portomartin/npmMutableLiveData

angular java livedata mutablelivedata

Last synced: 11 months ago
JSON representation

Java like LiveData pattern

Awesome Lists containing this project

README

          

# Example

## Animal class
```typescript
/* nosense class just for the next example */
export class Animal {

name: string;
race: string;
age: number;

constructor() {

this.name = "Tom";
this.race = "Cat";
this.age = 10;
}
}
```

## AppComponent
```typescript
import { Component } from '@angular/core';
import { NgFor } from '@angular/common';
import { Animal } from '../class/Animal.class';
import {MutableLiveData} from 'mutable-live-data'

@Component({
selector: 'app-root',
imports: [NgFor],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})

export class AppComponent {

animalA: MutableLiveData;
animalB: Animal;

animalsA: MutableLiveData>;
animalsB: Array;

constructor() {

/* observing a plain class */
this.animalA = new MutableLiveData(Animal);
this.animalB = new Animal();

this.animalA.observe(() => {
this.animalB = this.animalA.getValue();
});

/* observing array of same plain class */
this.animalsA = new MutableLiveData(Array);
this.animalsB = new Array();

this.animalsA.observe(() => {
this.animalsB = this.animalsA.getValue();
});
}

changeAnimal() {

var animal: Animal = this.animalA.getValue();
animal.name = "Tim";
animal.race = "Horse";
animal.age = 25;
this.animalA.postValue(animal);

var animals : Array = this.animalsA.getValue();
animals.push(animal)
this.animalsA.postValue(animals)
}
}
```

## html
```html

Angular Mutable LiveData

Animal


Name: {{animalB.name}}


Race: {{animalB.race}}


Age: {{animalB.age}}

Animals


{{animalsB}}


    • {{animal.name}}


  • Change Animal
    ```