Skip to content
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

Merged
merged 8 commits into from
Mar 25, 2018
Merged

refactor(storage): update storage plugin #154

merged 8 commits into from
Mar 25, 2018

Conversation

deebloo
Copy link
Member

@deebloo deebloo commented Mar 25, 2018

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

Copy link

@un33k un33k left a 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;
Copy link

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.

Copy link
Member Author

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;
}
Copy link

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.

Copy link

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.

Copy link
Member Author

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

key: '@@STATE',

/**
* Storage strategy to use. Thie defaults to LocalStorage but you
Copy link

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.

Copy link
Member

@amcdnl amcdnl left a 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,
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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

/**
* Custom serializer, defaults to JSON.stringify
*/
serialize: JSON.stringify,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing comma

@deebloo
Copy link
Member Author

deebloo commented Mar 25, 2018

@amcdnl don't merge yet. still adding tests and docs around it

@deebloo
Copy link
Member Author

deebloo commented Mar 25, 2018

@amcdnl @un33k I feel pretty good about this now. wanted to know if you all wanted to take one more look at it

@amcdnl amcdnl merged commit ff6f1f2 into master Mar 25, 2018
@amcdnl amcdnl deleted the storage branch March 25, 2018 23:12
@un33k
Copy link

un33k commented Mar 26, 2018

@deebloo Looks fantastic. One quick note on the storage?: StorageOption;. I wonder if this is redundant for custom storage engines. If so, the comment above it may need to be updated to reflect that.

Great job guys.

@deebloo
Copy link
Member Author

deebloo commented Mar 26, 2018

It would be yes. I can certainly add clarification in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants