angular-modellist

A bindable array wrapper for service data
Homepage:
1 person uses it
Author: 2062154? steelsojka

angular-modellist

Build Status NPM version Coverage Status

Why?

When storing model data in a service, you most likely will need to bind to it in your view(s). If we bind this data in multiple places we run the risk of loosing the instance if we aren't careful.

View the Github repo for code examples.

This service provides an object that wraps an array, but always keeps the same instance when operations are performed on it.

Use the getBindableList method to bind to directives.

NodeJS

Browser

The ModelList class will be available on the window object

API

Native methods:

Most array methods are supported in their native form except a couple:

  • join
  • pop
  • push
  • reverse
  • shift
  • unshift
  • splice
  • sort
  • forEach: Uses a minimal implementation if not supported
  • some
  • every
  • indexOf: Uses a minimal implementation if not supported
  • lastIndexOf
  • reduce
  • reduceRight
  • map: (Chainable) Mutates the array and does not return a new array
  • concat: (Chainable) Mutates the array and does not return a new array
  • filter: (Chainable) Mutates the array and does not return a new array
  • slice: (Chainable) Mutates the array and does not return a new array

If your browser doesn't support the method natively, it won't be available.

Custom methods:

  • get(Number:index): Gets an item at index
  • set(*, Number:index): (Chainable) Sets an item at index
  • clean(): (Chainable) Empties the array
  • overwrite(Array:array): (Chainable) Overwrites the array with the items in the new array
  • clone(): Returns a new ModelList object with a cloned list
  • getBindableList(): Returns the array. Only should be used for binding
  • pull(*): (Chainable) Removes object instances from the array

A length property is also kept in sync just like native array behaviour.

Static methods:

  • create(Array:array, [Boolean:clone]) Returns a new instance of ModelList
  • convert(Object:object, [Boolean:deep]) Converts all array instances into ModelList instances
comments powered by Disqus
This page was last updated about 3 years ago.