one-framework
TypeScript icon, indicating that this package has built-in type declarations

1.4.6 • Public • Published

About One Framework

On framework is built on top of RxJS, Lodash and React.

One framework gives structure to web applications by providing models and collections with a rich API, views with React components, and connects it all to your existing API over a RESTful JSON interface, and Websockets soon.

Within One framework data is represented by models, which can optionally belongs to a collection, that can be created, destroyed, and persisted to the server. models and collections are using RxJS, and they can be subscribed as them. So, any changes is going to be reflected on view state, keeping data in sync with the DOM with React components.

Sample

Model

A model manages entity properties, and takes care to broadcast changes along other application entities. Furthermore can sync with a backend through a REST API.

Collections

Collections helps you to group models, and encapsulate actions for them, like create, destroy. Further, it can sort models.

Model API

Properties

  • cid: string = Defines an unique identifier for each model instance, it is automatically attributed during model construction. Is highly recommended to never override this property.
  • collection: collection: Defines what collection this model should belongs to. If a model is created through a collection, this property is defined automatically. When this property is defined, any changes is going to be reflected at collection. If this property is defined during model construction, the model is automatically added to collection.
  • resource: string = Defines the resource which this model belongs to at backend, if the model belongs to a collection, this property should not be filled.
  • defaults:{[key: string]: any} = Defines default properties values.
  • validate: (attributes: any) => {[invalid: string]: string} = A function that should be executed to validate model.
  • parse: (attributes: any) => any = A Function that should be executed to parse model's properties.
  • idAttribute: string (default: 'id') = Defines what property that is going to be used to uniquely identify the model.
  • lastSet: number = Read only property that changes along models changes.
  • sync: Sync (default: ajax) = Defines what sync model will use to communicate with backend.
  • updateStream: Subject = An Observable of models' changes.
  • id: string | number = The property which uniquely identify the model, if idAttribute is defined, model.id will return idAttribute property.
  • url: string = Read only property which retrieves related app url followed by their resource, or collection's resource, if applied.

Methods

  • constructor(attributes?: any) = model's constructor.
  • set(newAttributes: any, options?: ISetOptions): model = Create or update model's properties.
  • unset(attribute: string): model = Opposed of set, it unset a model's property.
  • destroy(): model = Destroy the model.
  • fetch(options?: IFetchOptions, useSocket?: boolean): Observable = Fetch a model from backend.
  • save(useSocket?: boolean): Observable = Persists the model at backend.
  • patch(attributes: any, useSocket?: boolean): Observable = Patch the model at backend (send just desired properties, not all whole model).
  • delete(useSocket?: boolean): Observable = Delete the model at backend.
  • get(attribute?: string): any = Get a property from model, following Lodash's get signature.
  • has(attribute: string): boolean = Test if a property exists at model, following Lodash's has signature.
  • keys(): Array = Retrieve just model's keys.
  • values(): Array = Retrieve just model's values.
  • pick(...values: Array): any = Pick just desired model's properties, following Lodash's pick signature.
  • omit(...values: Array): any = Opposed of pick, following Lodash's pick signature.
  • equals(key: string, value: any | Array): boolean = Test if a property is equals a value or values.
  • extend(value: {[key: string]: any}): model = Extend model's properties following Lodash's extend signature.
  • chain(): _.LoDashExplicitObjectWrapper = Returns a Chainable Lodash Object.

Collection API

Properties

  • cid: string = Defines an unique identifier for each collection instance, it is automatically attributed during collection construction. Is highly recommended to never override this property.

  • id: string | number = Different of model, collection.id is an optional property that defines an id which represents the collection on backend post collection.resource. At this way, the collection's url is going to be defined as http(s?)://app.url/collection.resource/collection.id

  • model: typeof model = Defines what kind of model the collection will carry.

  • defaultOrder: {[key: string]: 'asc' | 'desc'} = Defines the default model's order.

      defaultOrder = {
        someProp: 'asc'
      }
    
  • resource: string = Defines the resource which this collection belongs to at backend. At this way, the collection's url is going to be defined as http(s?)://app.url/collection.resource/collection.id.

  • lastSet: number = Read only property that changes along models changes.

  • sync: Sync = Defines what sync model will use to communicate with backend.

  • updateStream: Subject<IcollectionOperation> = An Observable of models' changes.

  • url: string = Read only property which retrieves related app url followed by their resource, and id if provided.

Methods

  • constructor(model: typeof model, models?: Array | M | Array | any) = collection's constructor.
  • get(id?: string | number): Array = Retrieve all models or a single one identified by their model.id or model.cid.
  • getOne(id?: string | number): M = Get a single model identified by their model.id or model.cid.
  • has(id: string | number): boolean = Test if a model exists in a collection.
  • set(models: Array | M | Array | any, options?: ISetOptions): collection = Create or update a single model or a group of models.
  • reset(): void = Reset a collection and makes it empty.
  • destroy(): collection = Destroy a collection, not their models.
  • fetch(options?: IFetchOptions, useSocket?: boolean): Observable = Fetch models at backend defined by collection's url.
  • orderBy(iteratees?: Array | string, orders?: Array | string): Array = Returns a sorted collection's copy.
  • map(iteratee: ((model: M, index: number) => void) | string): Array = Project collection's models like Array.map and follows Lodash's map signature.
  • reduce(iteratee: (reduction: Array, model: any, index?: number) => Array): Array = Reduce collection's models like Array.reduce and follows Lodash's reduce signature.
  • each(iteratee: (model: M, index: number) => void): void - Iterate collection's models like Array.forEach and follows Lodash's each signature.
  • invokeMap(path: string, ...args: Array): Array = Invoke collection's following Lodash's reduce signature.
  • every(predicate: Function | {[key: string]: any} | string): boolean = Checks if predicate returns truthy for all models of collection, following Lodash's every signature.
  • some(predicate: Function | {[key: string]: any} | string): boolean = Checks if predicate returns truthy for any model of collection, following Lodash's some signature.
  • max(predicate: string): M = Computes the maximum value of models of collection, following Lodash's max signature.
  • min(predicate: string): M = Computes the minimum value of models of collection, following Lodash's min signature.
  • keyBy(predicate: Function | string): {[key: string]: any} = Creates an object composed of keys generated from the results of running each model of collection thru predicate, following Lodash's keyBy signature.
  • groupBy(predicate: Function | string): {[key: string]: Array} = Creates an object composed of keys generated from the results of running each model of collection thru predicate, following Lodash's groupBy signature.
  • filter(predicate: Function | {[key: string]: any} | string): Array = Filter collection's models like Array.filter and follows Lodash's filter signature.
  • reject(predicate: Function | {[key: string]: any} | string): Array = Opposed of filter and follows Lodash's reject signature.
  • find(predicate: Function | {[key: string]: any} | string, last?: boolean): M = Find a model inside a collection following Lodash's find signature.
  • findIndex(predicate: Function | {[key: string]: any} | string, last?: boolean): number = Find a model index inside a collection following Lodash's findIndex signature.
  • first(): M = Retrieves the first model.
  • last(): M = Retrieves the last model.
  • initial(amount?: number): Array = Retrieves the first amount model.
  • tail(amount?: number): Array = Retrieves the last amount model.
  • size(): number = Returns collection's models length.
  • chain(): _.LoDashExplicitArrayWrapper = Returns a Chainable Lodash Object.

Readme

Keywords

none

Package Sidebar

Install

npm i one-framework

Weekly Downloads

86

Version

1.4.6

License

ISC

Last publish

Collaborators

  • feliperohde