@mello-labs/api-tools
This project is intended for internal loanDepot/mello Labs use and is not (currently) publically supported.
Last updated a year ago by jerrolkrause .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mello-labs/api-tools 
SYNC missed versions from official npm registry.

This project is intended for internal loanDepot/mello Labs use and is not (currently) publically supported.

@mello-labs/api-tools

Installation

To install this library, run:

$ npm install @mello-labs/api-tools --save

Example Implementation

https://github.com/JerrolKrause/mello-labs-angular-starter/tree/master/src/app/shared/stores/api

Consuming your library

Once you have published your library to npm, you can import your library in any Angular application by running:

$ npm install @mello-labs/api-tools

and then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { ApiToolsModule, ApiReducer, ApiStatusReducer } from '@mello-labs/api-tools';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Add the ApiReducer and the ApiStatusReducer to NGRX
    StoreModule.forRoot({ api: ApiReducer, apiStatus: ApiStatusReducer}),
    // Specify your library as an import
    ApiToolsModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

To use the API Store automation service, see below.

import { ApiHttpService, ApiActions } from '@mello-labs/api-tools';

export class ApiService extends ApiHttpService {

  constructor(
  private http: HttpClient,
  private store: Store<IStore.root>,
  private router: Router
	) {
    super(http, store, router);
	}

    /** Sample store usage */
    public users = {
	    get: (update?: boolean) => this.getStore(ApiMap.users.endpoint, ApiMap.users, update),
		getOne: (user, update?: boolean) => this.getStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, update),
	    post: (user) => this.postStore(ApiMap.users.endpoint, ApiMap.users, user),
		put: (user) => this.putStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, user),
		delete: (user) => this.deleteStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, user)
    }
}

Create an action for each store property.

/** String enum of store properties/primary keys */
export enum ApiActions {
  // Example
  users = 'users',
}

In the Api map, specify the relationship from the api to your store.

import { AppStore } from '$shared';
import { ApiActions } from './api.actions';

export const ApiMap: AppStore.ApiMapping = {
  // Users Example
  users: {
    endpoint: '//jsonplaceholder.typicode.com/users',
    storeProperty: ApiActions.users,
    uniqueId: 'id',
  },
};

Once your library is imported, you can use its components, directives and pipes in your Angular application:

<!-- You can now use your library component in app.component.html -->
<h1>
  {{title}}
</h1>
<sampleComponent></sampleComponent>

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

Current Tags

  • 4.0.0                                ...           latest (a year ago)

16 Versions

  • 4.0.0                                ...           a year ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.8                                ...           2 years ago
  • 0.1.7                                ...           2 years ago
  • 0.1.6                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Downloads
Today 16
This Week 16
This Month 23
Last Day 1
Last Week 3
Last Month 14
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |