Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update memento.windowStorage.js #4

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "./bower_components"
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ build/Release
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# bower
bower_components
.idea/
31 changes: 31 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true,
"loopfunc": true,
"latedef": "nofunc",
"globals": {
"angular": false,
"$": false,
"document": false,
"window": false,
"_": false,
"location": false,
"localforage": false
}
}
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Memento is designed to support multiple storage methods; the method can be chose

myApp.config(['MementoProvider', function (MementoProvider) {
// Here, we can configure Memento to use a different storage method.
MementoProvider.storageMethod = 'window';
MementoProvider.setStorageMethod('window'); // also indexedDb, webSql, localStorage
}])

_NOTE: Memento currently only supports the 'window' storage method at this time._
Expand All @@ -30,15 +30,17 @@ With Memento as an app dependency, we can now inject Memento into a controller a
];

var memento = new Memento($scope.tasks);
or
var memento = new Memento($scope.tasks, 20); // you can set up the max history as 20

A Memento object acts as a stack of states for a given object. Thus, it exposes stack-like methods.

- `push(obj)`: Push an object onto the Memento stack, storing its state.
- `undo()`: Move backwards in the stack; return the previous state.
- `redo()`: Move forwards in the stack; return the next state.
- `revert()`: Return the original (first stored) object. This does not clear the stack.
- `canUndo()`: Returns true if we can move backwards in the stack - the object has a previous state.
- `canRedo()`: Returns true if we can move forwards in the stack - the object has a redo state.
- `push(obj).then(function (result) {})`: Push an object onto the Memento stack, storing its state.
- `undo().then(function (result) {})`: Move backwards in the stack; return the previous state.
- `redo().then(function (result) {})`: Move forwards in the stack; return the next state.
- `revert().then(function (result) {})`: Return the original (first stored) object. This does not clear the stack.
- `canUndo().then(function (result) {})`: Returns true if we can move backwards in the stack - the object has a previous state.
- `canRedo().then(function (result) {})`: Returns true if we can move forwards in the stack - the object has a redo state.

Rudimentary usage examples are provided in the `examples` directory.

Expand Down
22 changes: 22 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "memento-promise",
"version": "1.4.0",
"homepage": "https://github.com/iamdenny/memento-promise",
"authors": [
"Denny Lim <hi.iamdenny@navercorp.com>"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"./lib",
"test",
"tests"
],
"dependencies": {
"angular": "~1.x.x",
"angular-mocks": "~1.x.x",
"localforage": "~1.x.x"
}
}
1 change: 1 addition & 0 deletions dist/memento.core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/memento.indexedDb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/memento.js

This file was deleted.

1 change: 1 addition & 0 deletions dist/memento.localStorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/memento.webSql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/memento.windowStorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

<title>Memento example</title>

<script src="../lib/angular/angular.min.js"></script>
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/localforage/dist/localforage.min.js"></script>
<script src="../src/memento.core.js"></script>
<script src="../src/memento.windowStorage.js"></script>
<script src="../src/memento.indexedDb.js"></script>
<script src="../src/memento.localStorage.js"></script>
<script src="../src/memento.webSql.js"></script>
<script src="../src/memento.windowStorage.js"></script>
<script src="index.js"></script>

</head>
Expand All @@ -20,8 +24,8 @@ <h1>Memento Example - Todo List</h1>
<input type="text" data-ng-model="newTask">
<button type="submit">Add New</button>
</form>
<button data-ng-disabled="!weCanUndo()" data-ng-click="undo()">Undo</button>
<button data-ng-disabled="!weCanRedo()" data-ng-click="redo()">Redo</button>
<button data-ng-disabled="!canUndo" data-ng-click="undo()">Undo</button>
<button data-ng-disabled="!canRedo" data-ng-click="redo()">Redo</button>
<button data-ng-click="revert()">Revert</button>
</body>
<html>
48 changes: 40 additions & 8 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
angular.module('memento-example', ['Memento'])
.config(['MementoProvider', function (MementoProvider) {
// Here, we can configured Memento to use a different storage method.
MementoProvider.storageMethod = 'window';
MementoProvider.setStorageMethod('window');
// MementoProvider.setStorageMethod('localStorage');
// MementoProvider.setStorageMethod('webSql');
// MementoProvider.setStorageMethod('indexedDb');
}])
.controller('main', function ($scope, Memento) {
$scope.tasks = [
{ name: 'Update the memento.js README file' },
{ name: 'Add JSON deltas to main branch' }
];
$scope.canUndo = false;
$scope.canRedo = false;

var memento = new Memento($scope.tasks);

$scope.remove = function (index) {
$scope.tasks.splice(index, 1);
checkUndoRedo();
};

$scope.add = function (value) {
if (value === '') return;

$scope.tasks.push({ name: value });
memento.push($scope.tasks);
$scope.newTask = '';
memento.push($scope.tasks).then(function () {
$scope.newTask = '';
checkUndoRedo();
});
};

$scope.weCanUndo = function () { return memento.canUndo() };
$scope.weCanRedo = function () { return memento.canRedo() };
function checkUndoRedo() {
memento.canUndo().then(function (result) {
$scope.canUndo = result;
safeApply();
});
memento.canRedo().then(function (result) {
$scope.canRedo = result;
safeApply();
});
}

function safeApply() {
if (!$scope.$$phase) {
$scope.$digest();
}
}

$scope.undo = function () {
$scope.tasks = memento.undo() || $scope.tasks;
memento.undo().then(function (tasks) {
$scope.tasks = tasks || $scope.tasks;
checkUndoRedo();
});
};
$scope.redo = function () {
$scope.tasks = memento.redo() || $scope.tasks;
memento.redo().then(function (tasks) {
$scope.tasks = tasks || $scope.tasks;
checkUndoRedo();
});
};
$scope.revert = function () {
$scope.tasks = memento.revert();
memento.revert().then(function (tasks) {
$scope.tasks = tasks;
checkUndoRedo();
});
};
});
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var gulp = require('gulp'),
karma = require('gulp-karma'),

paths = {
scripts: "scripts/*.js",
scripts: "src/*.js",
spec: "spec/*.js",
dist: "dist"
};
Expand Down
5 changes: 3 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'./lib/angular/angular.min.js',
'./lib/angular-mocks/angular-mocks.js',
'./bower_components/angular/angular.min.js',
'./bower_components/localforage/dist/localforage.min.js',
'./bower_components/angular-mocks/angular-mocks.js',
'./src/*.js',
'./spec/*.js'
],
Expand Down
19 changes: 0 additions & 19 deletions lib/angular-mocks/.bower.json

This file was deleted.

42 changes: 0 additions & 42 deletions lib/angular-mocks/README.md

This file was deleted.

Loading