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

first initialization fail #1

Open
htrex opened this issue Mar 20, 2017 · 6 comments
Open

first initialization fail #1

htrex opened this issue Mar 20, 2017 · 6 comments

Comments

@htrex
Copy link

htrex commented Mar 20, 2017

I'm trying the following sample code in the constructor of an Injectable service in my app (Injectable services don't allow to use onInit):

        let testObject: any = {
            anArray: [
                'first string',
                'another string',
                'and even one more'
            ],
            aNumber: 2,
            anObject: {
                nestedValue: {
                    key: 'Woah this is nested!'
                }
            }
        };

        this.warehouse.set('test', testObject);

        this.warehouse.get('test').subscribe(data => {
            console.log('data',data);  // <-- returns null at first execution
        }
        );

At the absolute first execution, or at every first execution after I delete the 'ngx-warehouse' IndexedDB from the Chrome web browser, the get is returning null data.

@phillipcurl
Copy link
Owner

Hi @htrex - do you mind sharing what your NgxWarehouseModule import from your root AppModule looks like? If you you're able to point me to a repo or a working plunkr, that will also help me track down what might be going on here. Thanks!

@htrex
Copy link
Author

htrex commented Mar 21, 2017

Hi @phillipcurl and thanks for sharing ngx-warehouse, it's cool! Apart this glitch I haven't found any other problem so far.
My root appmodule is here https://gist.github.com/htrex/75df09fb7c839b41041aa35974aaef01 but unhopefully I can't share the app as it's for a customer.

I'm using a workaround in the constructor of my injectable "APICommonService" where I'm injecting ngx-warehouse and that does the trick for me

@Injectable()
export class APICommonService {
    public config: any;
    public configFn: any;

// ...

    private _allData:any = {};
    private _allData$:any = {};
    public dataEnum:any = {};

    private currentStorageVersion: string = '19';
    private storageVersion: string = localStorage.getItem('storageVersion');

 // ... 

    constructor( private http: Http,
                 public warehouse: Warehouse,
                 config: AppConfig
    ) {
        this.config = config.getConfig();
        this.configFn = config;

// ...

        this.warehouse.set('apiServiceLastInitTime', Date.now() ); // <-- I'm using it just for log and it does the trick !!!
    }

// ...

@phillipcurl
Copy link
Owner

@htrex No problem at all - I'm glad you're enjoying using it! Do you mind giving the custom config option a try in your AppModule? As per the docs/README, it should look something like this:

import { NgxWarehouseModule, WarehouseConfig, DRIVER_TYPE } from 'ngx-warehouse';

const config: WarehouseConfig = {
  driver: DRIVER_TYPE.DEFAULT,
  name: 'Your App',
  version: 1.0,
  storeName: 'key_value_pairs', // Should be alphanumeric, with underscores.
  description: 'A description of your app'
};

@NgModule({
  declarations: [...],
  imports: [
    ...
    NgxWarehouseModule.configureWarehouse(config),
    ...
  ],
  bootstrap: [...]
})

I haven't encountered this issue myself, but I'm thinking it might be caused by using the default config option. Using the NgxWarehouseModule.configureWarehouse method won't have a negative effect on performance, so you really shouldn't see any changes on your end.

In short, I think you're attempting to use the Warehouse service before it has been fully initialized. Using the configureWarehouse option should force that initialization and mitigate the issue. If this ends up being the case, I'll address the issue with the default config option to ensure this doesn't happen in the future.

@phillipcurl
Copy link
Owner

Hi @htrex, I just wanted to check in and see if you're still experiencing this issue. Please let me know if you have any additional details.

@htrex
Copy link
Author

htrex commented Mar 29, 2017

@phillipcurl sorry for the delay, I've a few deadlines nearing, should be able to check and report before next week I hope.

@htrex
Copy link
Author

htrex commented Apr 3, 2017

Sorry for the delay. I can confirm the issue even when using the suggested custom config on my App root module.

My test code is the following, placed in the constructor of "apiService" an Injectable service.

        this.warehouse.set('apiServiceLastInitTime', Date.now() );

        this.warehouse.get('apiServiceLastInitTime').subscribe(data => {
            console.log('apiServiceLastInitTime', data);  // <-- returns null at first execution
        });

I'm using a Chrome extension to delete the indexeddb database https://chrome.google.com/webstore/detail/clientmyadmin/mpfdmkiipkikcdbjlhgpjblpapkfcbjj?utm_source=chrome-app-launcher-info-dialog

After a database reset I'm always seeing a null value.

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

No branches or pull requests

2 participants