Skip to content
Merged
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
37 changes: 30 additions & 7 deletions doc/Persist.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ <h1 class="page-title">Source: Persist.js</h1>

// Check environment
if (db.isClient()) {
if (window.Storage !== undefined) {
this.mode('localforage');
this.mode('localforage');

localforage.config({
name: String(db.core().name()),
storeName: 'FDB'
});
}
localforage.config({
name: String(db.core().name()),
storeName: 'FDB'
});
}
};

Expand Down Expand Up @@ -190,6 +188,31 @@ <h1 class="page-title">Source: Persist.js</h1>
return this._mode;
};

/**
* Sets - if Persist is load in "localforage" mode - a custom driver which applies to the rules
* given by localforage, given here: https://localforage.github.io/localForage/#driver-api-definedriver
* @param driver A local forage driver definition
* @param callback A possible callback, which is executed after the customdriver was initialized
*/
Persist.prototype.customdriver = function(driver, callback) {
if (this.mode() !== 'localforage') {
throw 'No interface ready to set custom driver!';
}

var driverName = driver._driver; // copying the drivername to avoid possible variable modification errors
localforage.defineDriver(driver).then(function() {
return localforage.setDriver(driverName);
})
.then(function() {
if (callback) {
callback(null);
}
})
.catch(function(err) {
callback(err);
});
};

/**
* Gets / sets the driver used when persisting data.
* @param {String} val Specify the driver type (LOCALSTORAGE,
Expand Down
37 changes: 30 additions & 7 deletions js/lib/Persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ Persist.prototype.init = function (db) {

// Check environment
if (db.isClient()) {
if (window.Storage !== undefined) {
this.mode('localforage');
this.mode('localforage');

localforage.config({
name: String(db.core().name()),
storeName: 'FDB'
});
}
localforage.config({
name: String(db.core().name()),
storeName: 'FDB'
});
}
};

Expand Down Expand Up @@ -162,6 +160,31 @@ Persist.prototype.mode = function (type) {
return this._mode;
};

/**
* Sets - if Persist is load in "localforage" mode - a custom driver which applies to the rules
* given by localforage, given here: https://localforage.github.io/localForage/#driver-api-definedriver
* @param driver A local forage driver definition
* @param callback A possible callback, which is executed after the customdriver was initialized
*/
Persist.prototype.customdriver = function(driver, callback) {
if (this.mode() !== 'localforage') {
throw 'No interface ready to set custom driver!';
}

var driverName = driver._driver; // copying the drivername to avoid possible variable modification errors
localforage.defineDriver(driver).then(function() {
return localforage.setDriver(driverName);
})
.then(function() {
if (callback) {
callback(null);
}
})
.catch(function(err) {
callback(err);
});
};

/**
* Gets / sets the driver used when persisting data.
* @param {String} val Specify the driver type (LOCALSTORAGE,
Expand Down
Loading