Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ngx-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Public classes.
import { NgModule } from '@angular/core';
import { WebStorageService, CookiesStorageService, LocalStorageService, SessionStorageService, SharedStorageService } from './service/index';
import { CookiesStorageService, LocalStorageService, SessionStorageService, SharedStorageService } from './service/index';

export { CookieStorage, LocalStorage, SessionStorage, SharedStorage, SharedStorage as TempStorage } from './decorator/webstorage';
export { WebStorageService, CookiesStorageService, LocalStorageService, SessionStorageService, SharedStorageService, SharedStorageService as TempStorageService } from './service/index';
Expand Down
2 changes: 1 addition & 1 deletion src/service/local-storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebStorageService } from './webstorage.service';
import { localStorageUtility } from '../utility/index';
import { Injectable } from '@angular/core';
import { Observable, fromEvent, merge } from 'rxjs';
import { fromEvent, merge } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { NgxStorageEvent } from '../utility/storage/storage-event';

Expand Down
2 changes: 1 addition & 1 deletion src/service/session-storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebStorageService } from './webstorage.service';
import { sessionStorageUtility } from '../utility/index';
import { Injectable } from '@angular/core';
import { Observable, fromEvent, merge } from 'rxjs';
import { fromEvent, merge } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { NgxStorageEvent } from '../utility/storage/storage-event';

Expand Down
1 change: 0 additions & 1 deletion src/service/shared-storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { WebStorageService } from './webstorage.service';
import { sharedStorageUtility } from '../utility/index';
import { Injectable } from '@angular/core';
import { sharedStorage } from '../utility/storage/shared-storage';

@Injectable()
export class SharedStorageService extends WebStorageService {
Expand Down
5 changes: 3 additions & 2 deletions src/service/webstorage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebStorageUtility } from '../utility/webstorage.utility';
import { WebStorageServiceInterface } from './webstorage.interface';
import { Cache } from '../decorator/cache';
import { Observable } from 'rxjs';
import { delay, filter } from 'rxjs/operators';
import { delay, filter, first } from 'rxjs/operators';
import { NgxStorageEvent } from '../utility/storage/storage-event';
import { Resource } from './resource';
const merge = require('lodash.merge');
Expand Down Expand Up @@ -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)) {

Copy link
Copy Markdown
Contributor

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...

Copy link
Copy Markdown
Author

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.

return event.key === key;
}
return event.key === Config.prefix + key;
} else {
return event.key.indexOf(key) !== -1;
}
}),
first(), // take first event from events array
delay(30) // event should come after actual data change and propagation
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utility/storage/cookies-storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config, debug } from '../../config/index';
import { NgxStorage } from './storage';
import { StorageName, WebStorageUtility } from '../webstorage.utility';
import { Observable, interval } from 'rxjs';
import { interval } from 'rxjs';

export interface WebStorage extends Storage {
setItem(key: string, data: string, expirationDate?: Date): void;
Expand Down