Comments (7)
@Dedme Inject it like anything else...
import { DedicatedInstanceFactory, NgForage } from 'ngforage';
import { Injectable } from '@angular/core';
@Injectable({providedIn: 'root'})
export class MyService {
private readonly ngForage1: NgForage;
private readonly ngForage2: NgForage;
public constructor(dif: DedicatedInstanceFactory) {
this.ngForage1 = dif.createNgForage({name: 'foo'});
this.ngForage2 = dif.createNgForage({name: 'RTFM'});
}
}
from ngforage.
Hey. ngforage automatically handles this internally - it checks the configuration hash before every operation and calls localforage.createInstance()
if the hash has changed.
At the moment, this is roughly how things work:
class MyComponent implements OnInit {
private readonly ngf: NgForage;
public ngOnInit(): void {
this.ngf.name = 'foo'; // creates a store with the name 'foo';
}
public someMethod(): void {
this.ngf.getItem('a'); // Gets an item from store 'foo';
this.ngf.name = 'bar'; // creates a store called 'bar';
this.ngf.getItem('b'); // Gets an item from store 'foo';
this.nfg.name = 'foo'; // Switches back to store 'foo', reuses existing store.
this.ngf.getItem('c'); // Gets an item from store 'foo';
// The hash change occurs for any configuration change, not just the name.
}
}
For components you could simply add it to the providers, which would create a component-specific instance of ngforage:
@Component({
providers: [NgForage]
});
Such an approach does not currently exist for injectables and will be added in a future release; unfortunately, I don't know when I'll have time to implement it.
from ngforage.
Thank you for timely response.
from ngforage.
Hello, i am looking to use multiple named stores in services across my application, so this is in Injectables.
Is there a way i am able to manually configure something if the D.I. isn't there yet?
from ngforage.
Just wanted to close this out with that i solved this current by using the clone functionality.
in my service i am importing the defualt NGForage instance.
private ngf: NgForage;
constructor(ngfd: NgForage) {
this.ngf = ngfd.clone({storeName: 'newName'});
}
from ngforage.
@Dedme You could also use the dedicated instance factory: https://alorel.github.io/ngforage/docs/injectables/DedicatedInstanceFactory.html
from ngforage.
from ngforage.
Related Issues (20)
- An in-range update of @angular-devkit/build-ng-packagr is breaking the build 🚨 HOT 1
- NPM-Warnings on Angular 8 HOT 3
- An in-range update of @types/node is breaking the build 🚨 HOT 1
- An in-range update of @types/jasmine is breaking the build 🚨 HOT 4
- An in-range update of @types/jasminewd2 is breaking the build 🚨 HOT 2
- The documentation seems to be broken. HOT 1
- Docs: What's the difference between NgForage and NgForageCache? HOT 3
- Add sample from NgforageCache issue to docs
- Angular 9 support HOT 17
- Angular 8 AOT Unexpected value NgForageModule HOT 1
- localforage.d.ts
- Refreshing the page cannot fetch Store Value
- Angular 10 Support HOT 4
- Angular 11 support HOT 1
- The automated release is failing 🚨 HOT 1
- Error: NOT SUPPORTED: keyword "id", use "$id" for schema ID on Angular 13
- Need to iterate all keys
- Angular 14 support HOT 2
- Angular 16 Support HOT 4
- Angular 17 Support HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngforage.