Giter Site home page Giter Site logo

gerx's Introduction

geRx - Global Event Reactive Extensions

geRx is the data and state storage of your application, built on top of RxJs. The main advantage is ease of use.

geRx provides features for implementing onPush and onPull strategies, tracking request status, calling the application service method from anywhere.


Example
  • app.module.ts
import { GeRx } from 'geRx';

@NgModule({
  [...]
  providers: [GeRx],
  [...]
})
export class AppModule {}
  • app.service.ts
export class AppService {
  hello(): Observable<any>  {
    return of({message: 'Test geRx'}).pipe(delay(3000));
  }

  edit(text: string): Observable<any> {
    return of({message: text}).pipe(delay(3000));
  }
}
  • app.component.ts
@Component({
  selector: 'test-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestComponent implements OnInit, AfterViewInit {

  public entityName = 'hello';
  constructor(public geRx: GeRx, private appService: AppService) {}

  ngOnInit(): void {
    const geRxMethods: GeRxMethods = {
      show: this.appService.hello.bind(this.appService),
      edit: this.appService.edit.bind(this.appService)
    };
    return this.geRx.addEntity(this.entityName, geRxMethods);
  }

  ngAfterViewInit(): void {
    this.geRx.show(this.entityName);
  }

  onEdit(text): void {
    this.geRx.edit(this.entityName, text);
  }

  onClear(): void {
    this.geRx.cleanEntity(this.entityName);
  }
}
  • app.component.html
<p>Data$: {{ geRx.getData$(entityName) | async | json }}</p>
<p>Loading$: {{ geRx?.loading$(entityName) | async | json }}</p>
<p>
  <input type="text" #test />
  <button (click)="onEdit(test.value)">Edit</button>
  <button (click)="onClear()">Clear</button>
</p>

Description of the methods:

  • addEntity(name: string, methods: GeRxMethods, options?: GeRxOptions) - creating geRx entity
  • deleteEntity(name: string) - delete geRx entity
  • cleanEntity(name: string) - clearing .data and .data$ data in a geRx entity
  • getData$(entityName: string) - getting data using onPush strategy
  • getData(entityName: string) - getting data using onPull strategy
  • loading$ - request status at the moment of use onPush strategy
  • loading - request status at the moment of use onPull strategy
Methods for sending data and changing state of an entity
  • show(entityName: string, params?: any)
  • add(entityName: string, params?: any)
  • edit(entityName: string, params?: any)
  • delete(entityName: string, params?: any)
Types of parameters used
  • GeRxMethods: { show?: Observable<any>; add?: Observable<any>; edit?: Observable<any>; delete?: Observable<any>; }
  • GeRxOptions: { override: boolean; }
    • override - recreate an entity when it is reinitialized

gerx's People

Contributors

otapai avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.