• This repository has been archived on 12/Jan/2024
  • Stars
    star
    111
  • Rank 312,984 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

localForage bindings for Angular

ngforage

localforage bindings for Angular


NPM link


Installation

You can also npm install manually:

 npm install localforage@^1.10.0 ngforage@^9.0.0 # Angular 15
 npm install localforage@^1.10.0 ngforage@^8.0.0 # Angular 14
 npm install localforage@^1.9.0 ngforage@^7.0.0 # Angular 13
 npm install localforage@^1.5.0 ngforage@^6.0.0 # Angular 9
 npm install localforage@^1.5.0 ngforage@^5.0.0 # Angular 8
 npm install localforage@^1.5.0 ngforage@^4.0.0 # Angular 7
 npm install localforage@^1.5.0 ngforage@^3.0.0 # Angular 6
 npm install localforage@^1.5.0 ngforage@^2.0.0 # Angular 5
Basic Usage
  import {DEFAULT_CONFIG, NgForageOptions, NgForageConfig, Driver} from 'ngforage';
  
  @NgModule({
    providers: [
      // One way of configuring ngForage
      {
        provide: DEFAULT_CONFIG,
        useValue: {
          name: 'MyApp',
          driver: [ // defaults to indexedDB -> webSQL -> localStorage
            Driver.INDEXED_DB,
            Driver.LOCAL_STORAGE
          ]
        } as NgForageOptions
      }
    ]
  })
  export class AppModule{
    // An alternative way of configuring ngforage
    public constructor(ngfConfig: NgForageConfig) {
      ngfConfig.configure({
        name: 'MyApp',
        driver: [ // defaults to indexedDB -> webSQL -> localStorage
          Driver.INDEXED_DB,
          Driver.LOCAL_STORAGE
        ]
      });
    }
  }
  import {NgForage, Driver, NgForageCache, CachedItem} from 'ngforage';

  @Component({
    /* If you plan on making per-component config adjustments, add the services to the component's providers
     * to receive fresh instances; otherwise, skip the providers section.
     */
    providers: [NgForage, NgForageCache]
  })
  class SomeComponent implements OnInit {
    constructor(private readonly ngf: NgForage, private readonly cache: NgForageCache) {}
    
    public getItem<T = any>(key: string): Promise<T> {
      return this.ngf.getItem<T>(key);
    }
    
    public getCachedItem<T = any>(key: string): Promise<T | null> {
      return this.cache.getCached<T>(key)
        .then((r: CachedItem<T>) => {
          if (!r.hasData || r.expired) {
            return null;
          }
          
          return r.data;
        })
    }
    
    public ngOnInit() {
      this.ngf.name = 'SomeStore';
      this.cache.driver = Driver.LOCAL_STORAGE;
    }
  }
Store instances

It is recommended to declare NgForage and/or NgForageCache in providers if you're not using the default configuration. The running configuration hash is used to create and reuse drivers (e.g. different IndexedDB databases), therefore setting it on a shared instance might have unintended side-effects.

Defining a Driver
  1. Define a driver as described in the localForage docs
  2. Plug it in, either directly through localForage or through NgForageConfig:
import {NgModule} from "@angular/core";
import {NgForageConfig} from 'ngforage';
import localForage from 'localforage';

// Your driver definition
const myDriver: LocalForageDriver = {/*...*/};

// Define it through localForage
localForage.defineDriver(myDriver)
  .then(() => console.log('Defined!'))
  .catch(console.error);

@NgModule({})
export class AppModule {

  constructor(conf: NgForageConfig) {
    // Or through NgForageConfig
    conf.defineDriver(myDriver)
      .then(() => console.log('Defined!'))
      .catch(console.error);
  }
}

More Repositories

1

dropbox-v2-php

A PHP SDK for Dropbox's v2 API
PHP
50
star
2

rust-indexed-db

Future bindings for IndexedDB via web_sys
Rust
43
star
3

console-log-html

Adds console log output to the screen
CSS
31
star
4

typescript-lazy-get-decorator

Lazily evaluates a getter on an object and caches the returned value
TypeScript
31
star
5

patheditor2-mirror

Unofficial mirror of https://patheditor2.codeplex.com/ due to CodePlex shutting down
C++
21
star
6

mongoose-auto-increment-reworked

An auto-incrementing field generator for Mongoose 4 & 5
TypeScript
17
star
7

express-decorated-router

Define Express routes using TypeScript decorators
TypeScript
8
star
8

bound-decorator

A TypeScript/ES7 decorator for automatically binding methods to the class instance
TypeScript
5
star
9

melvor-action-workflows

Action Workflows
TypeScript
5
star
10

rollup-plugin-iife-wrap

Wraps your output chunks in an iife() with some commonly used global variables for better minification
TypeScript
4
star
11

ngx-sails

Angular bindings for communicating with the sails backend
TypeScript
4
star
12

heroku-cors-proxy

A CORS-enabled Express proxy server ready to deploy to Heroku.
JavaScript
4
star
13

alo-timer

An accurate JavaScript countdown manager
CSS
3
star
14

phpunit-auto-rerun

Allows failed PHPUnit tests to automatically rerun
PHP
3
star
15

dhm-dashboard

A userscript
TypeScript
3
star
16

userscript-utils

Useful tools for developing userscripts - in both CLI and API modes
JavaScript
3
star
17

ngx-decorators

Useful decorators for Angular 2 and above
TypeScript
2
star
18

localforage-driver-session-storage

sessionStorage support for localForage
TypeScript
2
star
19

rxutils

Utility functions for rxjs
TypeScript
2
star
20

node-cors-server

A CORS proxy server implemented in Node and Express
2
star
21

node-public-proxy-finder

Finds a free proxy for you
JavaScript
2
star
22

mongoose-transform-field-plugin

An automatic field transformation plugin for Mongoose 5. Any transformations are registered as save, update and findOneAndUpdate middleware.
TypeScript
2
star
23

localforage-driver-memory

in-memory localforage driver
TypeScript
2
star
24

alo-wamp

A self-updating WAMP stack with the latest binaries, always
HTML
1
star
25

alo-framework

An incredibly lightweight and flexible MVC framework for PHP 5.4+
PHP
1
star
26

typescript-proto-decorator

Sets a value on a class' prototype
JavaScript
1
star
27

fancy_constructor-rs

Derive a highly configurable constructor for your struct
Rust
1
star
28

node-ms-util

Converting millis to a human-readable string is a pain. It doesn't have to be.
JavaScript
1
star
29

netmonitor

Notifies you when you are connected or disconnected from the internet
Java
1
star
30

rollup-plugin-web-worker

A somewhat opinionated Rollup plugin for emitting web workers as chunks.
TypeScript
1
star
31

rollup-plugin-userscript

Generates userscript metablocks and, optionally, outputs a separate matadata file.
TypeScript
1
star