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
- Host: GitHub
- URL: https://github.com/portomartin/npmMutableLiveData
- Owner: MoaLaiSkirulais
- Created: 2024-11-28T01:25:33.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-28T01:50:31.000Z (over 1 year ago)
- Last Synced: 2024-11-28T02:32:48.526Z (over 1 year ago)
- Topics: angular, java, livedata, mutablelivedata
- Language: TypeScript
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```