Skip to content

Angular JS Service for managing service states (saving / restoring / invalidating)

Notifications You must be signed in to change notification settings

Mindera/angularStates

Repository files navigation

angularStates

Angular JS Service for managing service states (saving / restoring / invalidating)

Installation

Just do bower install angular-states.

Why?

This service is meant to be used as a 'top layer' on the AngularJS app, for saving, restoring, invalidating services/factories states. As mentioned in several AngularJS good practices lists and posts, using the controller's $scope can lead to a lot of disadvantages (difficult to reuse and test, doesn't separate Model/Controller concers, thight coupling, etc).

However, when keeping the model on services/factories it's sometimes necessary to maintain the state persistent across utilizations, which leads to further validation and (possibily) expiration over time. This service aims to facilitate that task and to make each service state logic easier to apply.

Note: Each service/factory values to be persisted should be made public so that the service can work correctly.

Usage

Include the 'angularStates' module as a dependency on your app, and include the 'StatesService' when it's needed.

angular.module('yourApp', ['angularStates', '..'])

Documentation

Members

angularStatesApp

angularStatesApp

Module of the Angular States.

StatesService

Angular JS Service for managing service states (saving / restoring / invalidating)

## angularStatesApp # angularStatesApp

Module of the Angular States.

Kind: global variable
Ngdoc: overview

StatesService

Angular JS Service for managing service states (saving / restoring / invalidating)

Kind: global variable
Ngdoc: service

StatesService.register(serviceInstance, keyName, fields)

Registers a service instance on the persistence service

Kind: static method of StatesService
Throws:

  • Error will throw if the current keyName is already in use
Param Type Description
serviceInstance Object registered service instance - for updating its state afterwards
keyName String key used for mapping items the each service
fields Array service properties that should be saved. Note: the elements of this array can be strings (name of the field) or objects. In case of object, they must use the following schema { name: 'property name', // String value: defaultValue, // any type expire: 1231 // Integer (time of expiration in milliseconds for the current field) }

StatesService.saveState(keyName)

Save the service state, based on the values mapped for the keyName provided

Kind: static method of StatesService

Param Type Description
keyName String key used for mapping items to the service

StatesService.recoverState(keyName)

Recovers the service state

Kind: static method of StatesService

Param Type Description
keyName String key used for mapping items to the service

StatesService.resetState(keyName)

Resets the service state and clears the storage of that service

Kind: static method of StatesService

Param Type Description
keyName String key used for mapping items to the service

StatesService.clearStorage(keyName)

Clears the service state on the persistence layer

Kind: static method of StatesService

Param Type Description
keyName String key used for mapping items to the service

About

Angular JS Service for managing service states (saving / restoring / invalidating)

Resources

Stars

Watchers

Forks

Packages

No packages published