11import * as constant from './constants' ;
2- import { setItem , getItem , removeItem } from 'localforage' ;
2+ import * as localForage from 'localforage' ;
33import { browserHistory } from 'react-router' ;
44import {
55 getSessionSuccess ,
@@ -68,14 +68,14 @@ export class sessionService {
6868 }
6969
7070 static saveSession ( session ) {
71- return setItem ( constant . USER_SESSION , session )
71+ return localForage . setItem ( constant . USER_SESSION , session )
7272 . then ( ( ) => instance . store . dispatch ( getSessionSuccess ( ) ) )
7373 . catch ( ( ) => instance . store . dispatch ( getSessionError ( ) ) ) ;
7474 }
7575
7676 static loadSession ( ) {
7777 return new Promise ( ( resolve , reject ) => {
78- getItem ( constant . USER_SESSION )
78+ localForage . getItem ( constant . USER_SESSION )
7979 . then ( ( currentSession ) => {
8080 if ( currentSession ) {
8181 resolve ( currentSession ) ;
@@ -88,21 +88,21 @@ export class sessionService {
8888 }
8989
9090 static deleteSession ( ) {
91- return removeItem ( constant . USER_SESSION ) . then ( ( ) => {
91+ return localForage . removeItem ( constant . USER_SESSION ) . then ( ( ) => {
9292 instance . store . dispatch ( getSessionError ( ) ) ;
9393 browserHistory . replace ( instance . redirectPath ) ;
9494 } ) . catch ( err => err ) ;
9595 }
9696
9797 static saveUser ( user ) {
98- return setItem ( constant . USER_DATA , user )
98+ return localForage . setItem ( constant . USER_DATA , user )
9999 . then ( ( user ) => instance . store . dispatch ( getUserSessionSuccess ( user ) ) )
100100 . catch ( ( ) => instance . store . dispatch ( getUserSessionError ( user ) ) ) ;
101101 }
102102
103103 static loadUser ( ) {
104104 return new Promise ( ( resolve , reject ) => {
105- getItem ( constant . USER_DATA )
105+ localForage . getItem ( constant . USER_DATA )
106106 . then ( ( currentUser ) => {
107107 if ( currentUser ) {
108108 resolve ( currentUser ) ;
@@ -115,7 +115,7 @@ export class sessionService {
115115 }
116116
117117 static deleteUser ( ) {
118- return removeItem ( constant . USER_DATA ) . then ( ( ) => {
118+ return localForage . removeItem ( constant . USER_DATA ) . then ( ( ) => {
119119 instance . store . dispatch ( getUserSessionError ( ) ) ;
120120 } ) . catch ( err => err ) ;
121121 }
0 commit comments