Skip to content

Latest commit

 

History

History
118 lines (97 loc) · 3.06 KB

File metadata and controls

118 lines (97 loc) · 3.06 KB

Firebase Transaction Manager

Angularjs Module that depends from AngularFire allows to make snapshots of an $firebaseObject, store versions in firebase, do rollback, go to prev version, undo, redo, go to a specific version and much more...

this repo is a fork of awesome https://github.com/marco64bit/Angular-Transaction-manager

Install

Bower

```sh bower install AngularFire-Transaction-manager --save ```

include firebase.transactionManager.js in your application

 <script src="scripts/transactionManager.js"></script>

add firebase.transactionManager to your angular module

var app = angular.module('myApp', ['firebase.transactionManager']);

try online demo

not yet.. comming...

or Open example folder and run

 npm install
 grunt install
 bower install

run grunt server in example folder

//////// doc deprecated... to be updated. ////////

API

works only with $firebaseObject (not with primitives) like this

var obj = $firebaseObject(ref);

TransactionManager.snapshot save the actual state of passed object ```js $scope.foo = {a: 1, b: "test"}; TransactionManager.snapshot($scope.foo); ``` the result object contains a key snapshot ```js {a: 1, b: "test", snapshot: [{a: 1, b: "test"}]} ``` you can call snapshot() more than 1 time, the result object will contain a list of all snapshot ```js $scope.foo = {a: 1, b: "test"}; TransactionManager.snapshot($scope.foo); $scope.foo.b = "changed"; TransactionManager.snapshot($scope.foo); // $scope.foo will be: //{a: 1, b: "test", snapshot: [{a: 1, b: "test"}, {a: 1, b: "changed"}]} ```
TransactionManager.rollback applies the last snapshot ```js $scope.foo = {a: 1, b: "test"}; TransactionManager.snapshot($scope.foo); $scope.foo.b = "test2"; // now foo is -> {a: 1, b: "test2"} TransactionManager.rollback($scope.foo); // now foo is -> {a: 1, b: "test"} ```
TransactionManager.canRollback returns true in case it has a snapshot and actual state is different from last snapshot ```js TransactionManager.canRollback($scope.foo); ```
TransactionManager.canRestorePrevious return true if passed object has a previous snapshot (old TransactionManager.prevVersion) ```js TransactionManager.canRestorePrevious($scope.foo); ```
TransactionManager.restorePrevious Restore to the state of previous snapshot version. ```js $scope.foo = {a: 1, b: "test"}; TransactionManager.snapshot($scope.foo); // now foo is -> {a: 1, b: "test"} $scope.foo.b = "test2"; TransactionManager.snapshot($scope.foo); // now foo is -> {a: 1, b: "test2"} TransactionManager.restorePrevious($scope.foo); // now foo is -> {a: 1, b: "test"} ```
TransactionManager.clear Remove all snapshots ```js TransactionManager.clear($scope.foo); ```
TransactionManager.hasSnapshot returns true if passed object has at least 1 snapshot ```js TransactionManager.hasSnapshot($scope.foo); ```