Skip to content

Commit

Permalink
fix(config): add persistance mode
Browse files Browse the repository at this point in the history
fixes #15102
  • Loading branch information
manucorporat committed Aug 11, 2018
1 parent f032769 commit db0049f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/src/global/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IonicConfig {
* Possible values are: `"ios"` or `"md"`.
*/
mode?: Mode;
_persist?: boolean;

isDevice?: boolean;
statusbarPadding?: boolean;
Expand Down
11 changes: 8 additions & 3 deletions core/src/global/ionic-global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'ionicons';

import { configFromURL } from '../utils/config';
import { configFromSession, configFromURL, saveConfig } from '../utils/config';
import { isIOS } from '../utils/platform';

import { Config } from './config';
Expand All @@ -16,10 +16,15 @@ Object.defineProperty(Ionic, 'queue', {

// create the Ionic.config from raw config object (if it exists)
// and convert Ionic.config into a ConfigApi that has a get() fn
const config = Ionic['config'] = Context['config'] = new Config({
const configObj = {
...Ionic['config'],
...configFromSession(),
...configFromURL()
});
};
const config = Ionic['config'] = Context['config'] = new Config(configObj);
if (config.getBoolean('_persist', false)) {
saveConfig(configObj);
}

// first see if the mode was set as an attribute on <html>
// which could have been set by the user, or by prerendering
Expand Down
10 changes: 10 additions & 0 deletions core/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export function setupConfig(config: IonicConfig) {
}

const IONIC_PREFIX = 'ionic:';
const IONIC_SESSION_KEY = 'ionic-persist-config';

export function configFromSession(): any {
const configStr = window.sessionStorage.getItem(IONIC_SESSION_KEY);
return configStr ? JSON.parse(configStr) : {};
}

export function saveConfig(config: any) {
window.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(config));
}

export function configFromURL() {
const config: any = {};
Expand Down

0 comments on commit db0049f

Please sign in to comment.