UNPKG

redux-orm-angular

Version:

Helpers for integrating Angular and Redux ORM

80 lines (79 loc) 3.56 kB
import { QuerySetSelector } from './queryset'; import { Model } from 'redux-orm'; /** * Select data from redux-orm * * This call replicates the API from redux-orm so the query syntax is the same. * Only "read" functions are available: all, get, hasId, withId */ export declare class ORMSelector { /** * The name of the model that we are querying */ modelName: string; /** * @param string modelName The name of the model to query */ constructor(model: Object | string); /** * Build a selector that queries the ORM * See the `all` function from http://tommikaikkonen.github.io/redux-orm/Model.html * * @return QuerySetSelector A function that gets all model instances from the state and allows further filtering */ all(): QuerySetSelector; /** * Build a selector that gets a model instance that matches properties in the `query` object * See the `get` function from http://tommikaikkonen.github.io/redux-orm/Model.html * * If there is no instance matching the properties, `null` will be returned and no exception will be thrown (contrary to the behavior of redux-orm). This helps dealing with these cases in Angular. * Warning: if there are multiple instances matching the properties, we will throw an error just like redux-orm does. * * @param object query The properties used to match a model instance * * @return function A function that gets a model instance from the state */ get(query: any): (state: any) => Model; /** * Build a selector that checks if a model instance with a given `id` exists in the store * See the `hasId` function from http://tommikaikkonen.github.io/redux-orm/Model.html * * @param string id The id to look for * * @return function A function that returns a boolean indicating if an entity with the id `id` exists in the state */ hasId(id: any): (state: any) => boolean; /** * Build a selector that gets a model instance with the specified `id` * See the `withId` function from http://tommikaikkonen.github.io/redux-orm/Model.html * * If there is no instance with that id, `null` will be returned and no exception will be thrown (contrary to the behavior of redux-orm). This helps dealing with these cases in Angular. * Warning: if there are multiple instances matching the properties, we will throw an error just like redux-orm does. * * @param string id The `id` used to match a model instance * * @return function A function that gets a model instance from the state */ withId(id: any): (state: any) => Model; /** * Get a model from a session populated from the current state * * @param Object state The current state * * @return Object A session model */ getModelFromState(state: any): any; } /** * Select data from redux-orm * * A helper function that can be used with angular-redux in the @select decorator or when calling * ngRedux.select (https://github.com/angular-redux/store/blob/master/articles/select-pattern.md) to select * models from redux-orm. * * The function replicates the API from redux-orm so the query syntax is the same. * Only "read" functions (withId, all) are available. * * @param {Object | string} model The name of the Model or the Model object that we are querying */ export declare function selectData(model: Object | string): ORMSelector;