-
Notifications
You must be signed in to change notification settings - Fork 41
Fixes for observe method #74
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
base: master
Are you sure you want to change the base?
Conversation
lekhmanrus
commented
Feb 5, 2019
- returned event, not events array
- fixed condition for exact match keys
- removed unused imports
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.
My mistake. don't apply commit b3b175a. sorry
@@ -68,14 +68,15 @@ export abstract class WebStorageService { | |||
filter((event: NgxStorageEvent) => { | |||
if (!key) { return true; } | |||
if (exactMatch) { | |||
if (key.startsWith(Config.prefix)) { | |||
if (!key.startsWith(Config.prefix)) { |
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.
Why? It doesn't make sens to add Config.prefix to the key below if the key already starts with prefix...
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.
Tbh, I don't remember exactly why I did that... but I suppose, it is because event.key
is a key without prefix, and that fix is to observe key
without prefix, so, for example:
Before:
if (exactMatch) {
if (key.startsWith(Config.prefix)) {
// if ('test'.startsWith('im.')) { // false
return event.key === key;
}
return event.key === Config.prefix + key;
// return 'test' === 'im.' + 'test'; // false
}
After:
if (exactMatch) {
if (!key.startsWith(Config.prefix)) {
// if (!'test'.startsWith('im.')) { // true
return event.key === key;
// return 'test' === 'test'; // true
}
return event.key === Config.prefix + key;
}
But it won't work for key
with prefix in both cases - Example 2:
Before:
if (exactMatch) {
if (key.startsWith(Config.prefix)) {
// if ('im.test'.startsWith('im.')) { // true
return event.key === key;
// return 'test' === 'im.test'; // false
}
return event.key === Config.prefix + key;
}
After:
if (exactMatch) {
if (!key.startsWith(Config.prefix)) {
// if (!'im.test'.startsWith('im.')) { // false
return event.key === key;
}
return event.key === Config.prefix + key;
// return 'test' === 'im.' + 'im.test'; // false
}
But I don't remember exactly. It was a while ago.