chore(storage): rename storage engine

This commit is contained in:
Max Lynch
2015-09-04 10:43:57 -05:00
parent 662e843a47
commit 417343593b
4 changed files with 29 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
import {Component} from 'angular2/angular2';
import {Control, ControlGroup} from 'angular2/forms';
import {App, Http, Storage, LocalStorage, SQLStorage} from 'ionic/ionic';
import {App, Http, Storage, LocalStorage, SqlStorage} from 'ionic/ionic';
let testUrl = 'https://ionic-api-tester.herokuapp.com/json';
let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404';
@@ -13,7 +13,7 @@ let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404';
class IonicApp {
constructor() {
this.local = new Storage(LocalStorage);
this.sql = new Storage(SQLStorage);
this.sql = new Storage(SqlStorage);
}
getLocal() {
this.local.get('name').then(value => {

View File

@@ -1,6 +1,17 @@
import {StorageStrategy} from './storage';
import {StorageEngine} from './storage';
export class LocalStorage extends StorageStrategy {
/**
* The LocalStorage storage engine uses the browser's local storage system for
* storing key/value pairs.
*
* Note: LocalStorage should ONLY be used for temporary data that you can afford to lose.
* Given disk space constraints on a mobile device, local storage might be "cleaned up"
* by the operating system (iOS).
*
* For guaranteed, long-term storage, use the SqlStorage engine which stores data in a file.
*/
export class LocalStorage extends StorageEngine {
constructor() {
super();
}

View File

@@ -1,10 +1,10 @@
import {StorageStrategy} from './storage';
import {StorageEngine} from './storage';
import * as util from 'ionic/util';
const DB_NAME = '__ionicstorage';
export class SQLStorage extends StorageStrategy {
export class SqlStorage extends StorageEngine {
static BACKUP_LOCAL = 2
static BACKUP_LIBRARY = 1
static BACKUP_DOCUMENTS = 0
@@ -14,7 +14,7 @@ export class SQLStorage extends StorageStrategy {
let dbOptions = util.defaults({
name: DB_NAME,
backupFlag: SQLStorage.BACKUP_NONE,
backupFlag: SqlStorage.BACKUP_NONE,
existingDatabase: false
}, options);
@@ -37,11 +37,11 @@ export class SQLStorage extends StorageStrategy {
_getBackupLocation(dbFlag) {
switch(dbFlag) {
case SQLStorage.BACKUP_LOCAL:
case SqlStorage.BACKUP_LOCAL:
return 2;
case SQLStorage.BACKUP_LIBRARY:
case SqlStorage.BACKUP_LIBRARY:
return 1;
case SQLStorage.BACKUP_DOCUMENTS:
case SqlStorage.BACKUP_DOCUMENTS:
return 0;
default:
throw Error('Invalid backup flag: ' + dbFlag);

View File

@@ -1,9 +1,14 @@
/**
* Storage is an easy way to store key/value pairs and other complicated
* data in a way that uses the best possible storage layer underneath.
* data in a way that uses a variety of storage engines underneath.
*
* For most cases, we recommend the SqlStorage system as it will store
* data in a file in the app's sandbox. LocalStorage should ONLY be used
* for temporary data as it may be "cleaned up" by the operation system
* during low disk space situations.
*/
export class Storage {
constructor(strategyCls: StorageStrategy) {
constructor(strategyCls: StorageEngine) {
this._strategy = new strategyCls();
}
get(key) {
@@ -17,7 +22,7 @@ export class Storage {
}
}
export class StorageStrategy {
export class StorageEngine {
get(key, value) {
throw Error("Not implemented");
}