pellejacobs / redux-persist-node-storage Goto Github PK
View Code? Open in Web Editor NEWRedux persist adaptor for Node localStorage
License: MIT License
Redux persist adaptor for Node localStorage
License: MIT License
@pellejacobs Thanks for sharing this project! We have added your library in the Mattermost redux https://github.com/mattermost/mattermost-redux/blob/master/package.json#L37.
Would you consider adding the MIT license as a LICENSE file?
If you use a license it would make it easy to add your work to other open source projects, and we'd love to keep your work in ours.
Thanks kindly for your consideration and let me know if you have any questions!
Please see more context here: mattermost/mattermost-redux#1179 (review).
redux-persist just switched to requiring promise based storage in v5.0.0-beta.13
Unfortunately it is going to be a pain to get everyone updated. Technically the storage can support both (like AsyncStorage and localforage) but since this module is specific to redux-persist may was well just go 100% promises and make the peer dep be redux-persist@5
If I import the library (in NativeScript) like it says in the docs: import { AsyncNodeStorage } from 'redux-persist-node-storage'
I get the following error: TypeError: Cannot read property 'slice' of undefined when importing
UPDATE:
This is because of how the NativeScript environment is setup, read my comment below for explanation
I get this error as soon as I try to import AsynchNewStorage:
How do I fix this?
ERROR in ./~/node-localstorage/LocalStorage.js
Module not found: Error: Cannot resolve module 'fs' in /home/simran/Desktop/frontend/node_modules/node-localstorage
@ ./~/node-localstorage/LocalStorage.js 9:7-20
ERROR in ./~/graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /home/simran/Desktop/frontend/node_modules/graceful-fs
@ ./~/graceful-fs/graceful-fs.js 1:9-22
ERROR in ./~/graceful-fs/fs.js
Module not found: Error: Cannot resolve module 'fs' in /home/simran/Desktop/frontend/node_modules/graceful-fs
@ ./~/graceful-fs/fs.js 3:9-22
From my reading of the code, it seems like it's not. For example, in index.ts
getItem (key: string) {
return new Promise<string>((resolve, reject) => {
try {
const storedValue = this.localStorage.getItem(key)
process.nextTick(() => resolve(storedValue))
} catch (e) {
reject(e)
}
})
}
localStorage.getItem()
is called in the body of the resolver function, which the MDN says is executed immediately. I believe this means the calling thread is blocked by localStorage.getItem()
. I understand all "asynchronous" code blocks the calling thread to some extent, but it might be helpful to clarify somewhere that reading/writing is using the blocking sync API.
Thank you for writing this project, and thank you for your time!
I installed redux-persist-node-storage and use the example, but a have problem: TypeError: fs.statSync is not a function
LocalStorage.prototype._init = function() {
var _MetaKey, _decodedKey, _keys, e, error, error1, i, index, k, len, stat;
try {
stat = fs.statSync(this._location); //the problem
if ((stat != null) && !stat.isDirectory()) {
throw new Error("A file exists at the location '" + this._location + "' when trying to create/open localStorage");
}
...
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.