-
Notifications
You must be signed in to change notification settings - Fork 406
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
refactor(storage): update storage plugin #154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
serialize: JSON.stringify, | ||
deserialize: JSON.parse | ||
}; | ||
|
||
export function engineFactory(engine: StorageOption): StorageEngine { | ||
if (engine === StorageOption.LocalStorage) { | ||
return localStorage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are still bound to the global context.
return localStorage
is the same as
return global.localStorage
Where is the handling of the custom storage engine, let's say on mobiles via NativeScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See StorageEngine
getItem(key): any; | ||
setItem(key, val): void; | ||
removeItem(key): void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add length
, key
and clear
as well to make it fully compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else looks great. We just need to test the non-default option, for example sessionStorage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill make sure it is tested. Just wanted your input before I went to far
docs/plugins/storage.md
Outdated
key: '@@STATE', | ||
|
||
/** | ||
* Storage strategy to use. Thie defaults to LocalStorage but you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simple typo This
for Thie
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/** | ||
* Custom deseralizer. Defaults to JSON.parse | ||
*/ | ||
deserialize: JSON.parse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@un33k - If passing a different storage engine breaks, wouldn't this break too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually something I am looking into now. writing tests around a simple custom storage option now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amcdnl so it will break depending on what you do with your implementation. it is easy enough to pass a custom serializer/deserialzer though so im not to concerned. maybe a documentation issue more then anything else
docs/plugins/storage.md
Outdated
/** | ||
* Custom serializer, defaults to JSON.stringify | ||
*/ | ||
serialize: JSON.stringify, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing comma
@amcdnl don't merge yet. still adding tests and docs around it |
@deebloo Looks fantastic. One quick note on the Great job guys. |
It would be yes. I can certainly add clarification in the docs |
Updates storage plugin to allow you to pass in your own storage implementation.
@un33k wanted your input since you had opened a PR for this previously. wanted to know what you thought. should address #140