0.1.4 • Published 5 years ago

uppy-store-ngrx v0.1.4

Weekly downloads
163
License
ISC
Repository
github
Last release
5 years ago

Uppy Store for Ngrx usage

npm npm version

Produce opportunity to use Ngrx state as a state of Uppy Store. Also package provides interfaces to convenient work Uppy with TypeScript.

Installation

$ npm install uppy-store-ngrx --save

Usages

  1. Connect UppyStoreNgrx to your reducers. In this example for state name of Uppy store uses default value uppy.

reducers.ts

import {
  ...
  ActionReducerMap,
} from '@ngrx/store';

import * as UppyStoreNgrx from 'uppy-store-ngrx';

export interface State {
  ...
  uppy: UppyStoreNgrx.State;
}

export const reducers: ActionReducerMap<State> = {
  ...
  uppy: UppyStoreNgrx.reducer
};
  1. Connect UppyStoreNgrx to your Uppy instance:

uploader.service.ts

import { Inject, Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import * as Uppy from 'uppy/lib/core/Core';
import { Observable } from 'rxjs/Observable';
import { createNgrxStore, INgrxStore, IUppy, UppyFile, UppyFiles, FileType } from 'uppy-store-ngrx';

import * as fromRoot from './reducers';

export interface MyFile {
  id: number;
  name: string;
  type: FileType;
}

@Injectable()
export class UploaderService {
  private uppy: IUppy<INgrxStore<fromRoot.State, MyFile>, MyFile>;
  
  constructor(
    private store: Store<fromRoot.State>
  ) {
    this.uppy = Uppy({
      store: createNgrxStore<fromRoot.State, MyFile>({
        store: this.store,
      }),
    });
  }

  // Async method to get files from Uppy state
  getFilesStream(): Observable<Array<UppyFile<MyFile>>> {
    return this.uppy.store.getFiles().map(files => (<any> Object).values(files));
  }

  // Sync method to get files from Uppy state
  getFiles(): Array<UppyFile<MyFile>> {
    let files: Array<UppyFile<MyFile>> = [];
    this.getFilesStream().take(1).subscribe(_files => files = _files);

    return files;
  }
}

Function createNgrxStore supports next options:

store: Store<T>; // Ngrx store.
id?: any; // Name of Uppy store in Ngrx state. Default name is `uppy`.
selector?: any; // Selector to select Uppy store from Ngrx state.
0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago