PillowPillow / ng2-webstorage

Localstorage and sessionstorage manager - Angular service
MIT License
428 stars 92 forks source link

Decorators invoked before `Ng2Webstorage.forRoot` sets prefix/separator #83

Closed ross-nordstrom closed 6 years ago

ross-nordstrom commented 6 years ago

When I upgraded from 1.8.0 to 2.0.1, my storage is lost when I reopen my app in a new tab. When I set some breakpoints, it looks like this is because the decorators (@LocalStorage, @SessionStorage) are getting invoked (decorators/webStorage.js) before my config is set (interfaces/config).

I've got a multi-module application, and I'm setting forRoot({prefix: 'foo', separator: '/', caseSensitive: false}) in my CoreModule, which is imported and used by all other modules.

Any ideas? This worked fine for us in 1.8.0

Relevant libs:

    "@angular/cli": "1.6.3",
    "@angular/core": "5.1.2", // same for @angular/*
    "@angular/material": "5.0.2",
    "ngx-webstorage": "2.0.1",
PillowPillow commented 6 years ago

Hi, @ross-nordstrom , the behavior that you described is totally normal. Even if the decorator triggers before the configuration, their executions delayed until the app initialization. I added this behav to fix the configuration usage by decorators with the v2.0.0. (issue #55)

On the other hand, i m using the library this way and it works like a charm.

You said that your CoreModule contains the forRoot call, how did you declare your module exactly? The bug could come from a multiple instanciation of the Ng2Webstorage. Personnaly, to avoid any error i'm calling every configurations from my main module (app generally) and i declare in the shared one only the base modules (do not call the forRoot or whatever name for module init method).

Without more informations i can't really help you since i can't reproduce the issue from my side. Maybe you could try to clear the localstorage and reload your application seeing if their is any ng2-webstorage|xxxx variables stored.

regards

PillowPillow commented 6 years ago

I'm closing this issue since there isn't any news since more than 15days. Feel free to open another if you still encounter this issue.