jeremydurham / persist-js Goto Github PK
View Code? Open in Web Editor NEWPersistJS is a JavaScript client-side persistent storage library
Home Page: http://pablotron.org/software/persist-js/
License: MIT License
PersistJS is a JavaScript client-side persistent storage library
Home Page: http://pablotron.org/software/persist-js/
License: MIT License
Please patch the remove call in localStorage:
// get value
val = this.store.getItem(key);
local storage remove should read
remove: function(key, fn, scope) {
var val;
// expand key
key = this.key(key);
// get value
val = this.store.getItem(key);
// delete value
this.store.removeItem(key);
if (fn){
fn.call(scope || this, (val !== null), val);
}
}
instead of
remove: function(key, fn, scope) {
var val;
// expand key
key = this.key(key);
// get value
val = this.getItem(key);
// delete value
this.store.removeItem(key);
if (fn){
fn.call(scope || this, (val !== null), val);
}
}
If Safari private mode is enabled localstorage can't be used, does this support the use cookies instead?
The title says it all. I would like to pull this into a project I am working on but didn't want to fork and register a Bower package on my fork.
Would be useful to be able to force a backend.
Hi,
I am thinking of implementing offline feature based on user. For example. if user 1 is logged in when internet connection is on and logged off when the internet connection is off. Meanwhile, want to store the data accessed by the user 1. Like that, i want to do the same for User 2.
I want to maintain the data for al teast a day. But, it should work based on the user.
I am planning the user id and password in local when the user logged in.
I am not sure, whether persistant.js will support this kind of feature.
Kindly let me know your thoughts on this.
Thanks
Rajesh khanna
License has to be included so it's better to be included in source source file!
What do you say?
i am using persist.min.all js in my website for local storage although there is no flash content on my website but Firefox is giving error "Firefox has prevented the outdated plugin from running in your website " its because persist min all check for the shock-wave version .
Does this have impact on my website JavaScript if someone has explicitly blocked the flash content from their browser .as still the code runs the flash check in persist min all
Hi,
Is there any way to retrieve the key:value pairs from the store in a batch format? JSON perhaps? I was hoping for a way to loop through and build a query string based on what's been saved.
Thanks.
I think it would be common to use store.remove inside store.iterate. If a for..in loop was used we could iterate and remove/delete keys.
Edit:
The issue is that currently a for loop is used, and as the number of keys changes (ie during a remove) so does the referenced length value, which means we won't be iterating through the entire collection. A for...in loop will iterate over all items in the collection even after a delete since it doesn't depend on the length of the collection.
What is the order in which PersistJS tries to save the data? Is it:
flash: Flash 8 persistent storage.
gears: Google Gears-based persistent storage.
localstorage: HTML5 draft storage.
whatwg_db: HTML5 draft database storage.
globalstorage: HTML5 draft storage (old spec).
ie: Internet Explorer userdata behaviors.
cookie: Cookie-based persistent storage.
Can we somehow influence this order?
The line at around 798 in the Remove function with the code "val = this.store[key];" should read "val = this.store.getItem[key];"
The README says 0.3.0, but the newest tagged release is 0.2.0.
Hello I'm trying to use persist-js on my React preject but I'm getting this error:
Line 6: 'Persist' is not defined no-undef
Search for the keywords to learn more about each error.
The problem is that I don't know how to import the lib correctly
I have tried this:
import 'persist-js' and
import Persist from 'persist-js'
With no luck.
Some workaround?
I was trying the examples and when i try to run test_flash, it does not work in IE6. I have flash version 10. The type is shown as flash but when i try to save, it gives me the object is not supported error.
I cant use the userData behaviour as i have pages in multiple directories.
I want to update the value of an item, I am not finding it possible to do this so I decided to remove it and write it again, in looking at that I got the following error
which returns
TypeError: this.getItem is not a function
...key,fn,scope){var val;key=this.key(key);val=this.getItem(key);this.store.removeI...
I narrowed down and found I just couldn't remove the item.
It is the correct data store and item I referring to.
I can provoke this with something as simple as
var store = new Persist.Store('external_img_store');
store.remove("urls");
however If I do
store.get('urls', function (ok, val) {
var currenturl_list;
if (ok) {
currenturl_list = val.split(",");
console.log(currenturl_list);
}
});
I see all the urls I have stored in there.
Any ideas?
Can you add this to a cdn like cndjs?
It would be good to have this as something I can do. How would you accomplish this?
Is it going to be used?
Please ignore. Entered in error. Was intending to enter in another repository--node-persist
var store = new Persist.Store('store', {
swf_path: this.options.rootPath + 'assets/js/persist.swf'
})
store.save('h', 'heldadasdasdlo');
console.log(store.get('h'));
Currently when I run the script I receive this error from the console.log output: (Chrome):
Uncaught TypeError: Object # has no method 'get'
(Firefox):
this.el.get is not a function
...key,val);return old_val;},remove:function(key){var val;key=esc(key);val=this.el....
Both are on line 138. I am using the latest version of persist and have tried everything on my end and still no go.
Thanks,
Daniel
Firstly, great code bud, really got me out of a hole with too many cookies being set on the client:
Bug: The "search_order" methods place cookies before IE - meaning that cookies get implemented on IE rather than userdata. Just need to be swapped around.
A suggestion is to handle the various size limitations in the library, by chopping up stored data into slices that fits into the current size limitation. This would effectively make the interface size-agnostic to use, with performance declining by large-sized values on small-sized storage methods.
I cannot currently contribute with this code myself, but I wanted to get it out there for this library. If you don't see it as a fit, I wanted to encourage someone writing a few code lines as a wrapper to this library which adds this functionality.
Possible to add it onto bower listing?
After hours of struggling, I found out that when removing keys, the domain reference is not the same as when you set it.
Add .md extension to README and TODO to make GitHub render them with some style.
I'm using your persist.js (Version : 0.2.0) library as it handles the fall back mechanism in the background. It works fine if i have the cookies turned on, but not otherwise.
Do you have any thoughts on this issue ?
In firefox with the cookie turned OFF, I get Security error" code: "1000 , if i use http://localhost:xxxx and I dont see any error if i use 127.0.0.1 instead of localhost but still no data gets collected.
Thanks
Jay
I have an application where the user uses a bookmarklet to save images to their localStorage on our site - (user clicks save images - goes to our site with encoded url list of images to save) We save those images into a persist store, the type being used is localStorage.
(the site needs login to see it so I won't provide a link - right now anyway this is me doing stuff on localhost)
anyway if I have an url /images/external?list=encodedlistofurls
addtopersist = function(store_name){
try {
var store = new Persist.Store(store_name);
console.log("type = " + Persist.type);
//Persist.remove('cookie');
store.set('urls', currenturl_list);
store.save();
} catch (e) {
console.log(e);
}
}
addtopersist("external_img_store");
If I go to /images/external the Persist store is queried for the external_img_store, if I go to /images/external in the same tab I was just in where I loaded the image urls it works and I get all the urls back, if I open up a new window and go to /images/external if I go to my site and then navigate to /images/external I don't get the urls either.
It used to be that it worked that I could just paste in /images/external and see the images I had saved recently, or I could navigate there, but no longer (this if Firefox 46.0 right now but others have reported it in other browsers) , is anyone familiar with anything that could be changed with localStorage across that would cause this to not work anymore ?
It seems like persist-js doesn't allow you to use sessionStorage. Is persist-js safe (at least as safe as js-accessible cookies) for a client-side session?
Problem:
If FireFox is reading the website HTML, JS, etc. from file://, and you use persist.js to do your storage, It will be discarded upon browsing to a new site.
Solution and Explanation:
In more detail here: http://blog.ideaday.de/max/2011/10/persist-js-does-not-work-with-firefox-offline/
//detect FireFox. If it's the Fox, AND running locally remove localstorage
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent) && window.location.protocol == 'file:'){
Persist.remove('localstorage');
}
Hope this gets patched in :-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.