Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
walid1992d committed Aug 8, 2018
1 parent 3a6cc0d commit bbffcf1
Show file tree
Hide file tree
Showing 3,855 changed files with 212 additions and 811,477 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 3 additions & 1 deletion . npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
lib/
lib/
tsconfig.json
node_modules
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 25 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
export interface TEST {
name: string;
price: number;
import 'reflect-metadata';
import { Observable } from 'rxjs';
export declare class StateStoreService {
private dataChanged;
private state;
private config;
initStateStore(config: StateConfig): void;
setValue(key: string, value: any, saveToStorage?: boolean): void;
private saveState;
private loadState;
setBulkValues(dataObject: any, saveToStorage?: boolean): void;
getValue(key: string): any;
getState(): any;
private loadFromStorage;
private encrypt;
private decrypt;
stateChanged(key?: any): Observable<any>;
}
export declare function getStateStoreService(): StateStoreService;
export interface StateConfig {
version: string;
appName: string;
initialState: any;
encryptionKey: string;
migrateFunction: any;
}
export declare const data: TEST;
141 changes: 135 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,136 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
exports.data = {
name: '1',
price: 1,
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import 'reflect-metadata';
import { Injectable, ReflectiveInjector } from 'injection-js';
import * as CryptoJS from 'crypto-js';
import { Subject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { fromJS } from 'immutable';
import * as LZUTF8 from 'lzutf8';
var StateStoreService = /** @class */ (function () {
function StateStoreService() {
this.dataChanged = new Subject();
this.config = {
version: 'v1.0',
appName: 'Insta State App',
encryptionKey: 'B7aTOSBV4iyfDYHbcyRtefWc6NUO21DI',
initialState: {
testStateValue: 'Hello World',
},
migrateFunction: function (initialState, savedState) {
}
};
}
StateStoreService.prototype.initStateStore = function (config) {
this.config = config;
this.config.initialState.version = this.config.version;
this.loadFromStorage();
};
StateStoreService.prototype.setValue = function (key, value, saveToStorage) {
if (saveToStorage === void 0) { saveToStorage = true; }
this.state[key] = value;
this.dataChanged.next(key);
if (saveToStorage) {
if (!localStorage.getItem(this.config.appName)) {
return;
}
var savedState = this.loadState();
if (!savedState) {
return;
}
var storedData = savedState;
storedData[key] = value;
this.saveState();
}
};
StateStoreService.prototype.saveState = function () {
var encrypted = this.encrypt(JSON.stringify(this.state)).toString();
var state = LZUTF8.compress(encrypted);
localStorage.setItem(this.config.appName, state);
};
StateStoreService.prototype.loadState = function () {
if (!localStorage.getItem(this.config.appName)) {
return null;
}
var nums = localStorage.getItem(this.config.appName).split(',').map(function (n) { return parseInt(n); });
var bytes = new Uint8Array(nums);
var data = LZUTF8.decompress(bytes);
if (!JSON.parse(this.decrypt(data))) {
return null;
}
return JSON.parse(this.decrypt(data));
};
StateStoreService.prototype.setBulkValues = function (dataObject, saveToStorage) {
var _this = this;
if (saveToStorage === void 0) { saveToStorage = true; }
Object.keys(dataObject).forEach(function (key) {
_this.state[key] = dataObject[key];
});
if (saveToStorage) {
var savedState = this.loadState();
if (!savedState) {
return;
}
var storedData_1 = savedState;
Object.keys(dataObject).forEach(function (key) {
storedData_1[key] = dataObject[key];
});
this.saveState();
}
Object.keys(dataObject).forEach(function (key) {
setTimeout(function () {
_this.dataChanged.next(key);
}, 100);
});
};
StateStoreService.prototype.getValue = function (key) {
return fromJS(this.state).toJS()[key];
};
StateStoreService.prototype.getState = function () {
return fromJS(this.state).toJS();
};
StateStoreService.prototype.loadFromStorage = function () {
if (!localStorage.getItem(this.config.appName)) {
this.state = fromJS(this.config.initialState).toJS();
this.saveState();
return;
}
var savedState = this.loadState();
if (!savedState) {
this.saveState();
return;
}
var state = savedState;
if (state.version !== this.config.initialState.version) {
state = this.config.migrateFunction(this.config.initialState, state);
state.version = this.config.initialState.version;
}
this.state = state;
this.saveState();
this.dataChanged.next('');
};
StateStoreService.prototype.encrypt = function (data) {
return CryptoJS.AES.encrypt(data, this.config.encryptionKey);
};
StateStoreService.prototype.decrypt = function (data) {
return CryptoJS.AES.decrypt(data, this.config.encryptionKey).toString(CryptoJS.enc.Utf8);
};
StateStoreService.prototype.stateChanged = function (key) {
var _this = this;
if (key === void 0) { key = null; }
return this.dataChanged.pipe(filter(function (storeKey) { return !key || key == storeKey || storeKey == ''; }), map(function () { return key ? _this.state[key] : _this.state; }));
};
StateStoreService = __decorate([
Injectable()
], StateStoreService);
return StateStoreService;
}());
export { StateStoreService };
var ServicesInjector = ReflectiveInjector.resolveAndCreate([StateStoreService]);
export function getStateStoreService() {
return ServicesInjector.get(StateStoreService);
}
1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class StateStoreService {

public initStateStore(config: StateConfig) {
this.config = config;
this.state.version = this.config.version;
this.config.initialState.version = this.config.version;
this.loadFromStorage();

}

public setValue(key: string, value: any, saveToStorage: boolean = true) {

this.state[key] = value;
Expand Down Expand Up @@ -101,7 +101,7 @@ export class StateStoreService {
return fromJS(this.state).toJS()[key];
}

private getState():any {
public getState():any {
return fromJS(this.state).toJS();
}
private loadFromStorage() {
Expand All @@ -119,9 +119,10 @@ export class StateStoreService {
}


const state = savedState;
let state = savedState;
if(state.version !== this.config.initialState.version) {
this.config.migrateFunction(this.config.initialState,state);
state = this.config.migrateFunction(this.config.initialState, state);
state.version = this.config.initialState.version;
}

this.state = state;
Expand All @@ -146,7 +147,7 @@ export class StateStoreService {
public stateChanged(key = null): Observable<any> {
return this.dataChanged.pipe(
filter(storeKey => !key || key == storeKey || storeKey == ''),
map((key) => key ? this.state[key] : this.state)
map(() => key ? this.state[key] : this.state)
);
}

Expand All @@ -158,7 +159,7 @@ export class StateStoreService {
}

const ServicesInjector: Injector = ReflectiveInjector.resolveAndCreate([StateStoreService]);
export function getStateStoreService() {
export function getStateStoreService(): StateStoreService {
return ServicesInjector.get(StateStoreService);
}
export interface StateConfig {
Expand Down
Empty file removed lib/models.ts
Empty file.
1 change: 0 additions & 1 deletion node_modules/.bin/tsc

This file was deleted.

1 change: 0 additions & 1 deletion node_modules/.bin/tsserver

This file was deleted.

21 changes: 0 additions & 21 deletions node_modules/@types/crypto-js/LICENSE

This file was deleted.

16 changes: 0 additions & 16 deletions node_modules/@types/crypto-js/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/aes/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/core/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/enc-base64/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/enc-hex/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/enc-latin1/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/enc-utf16/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/enc-utf8/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/evpkdf/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/format-hex/index.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions node_modules/@types/crypto-js/format-openssl/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-md5/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-ripemd160/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha1/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha224/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha256/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha3/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha384/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions node_modules/@types/crypto-js/hmac-sha512/index.d.ts

This file was deleted.

Loading

0 comments on commit bbffcf1

Please sign in to comment.