Skip to content

Commit db0049f

Browse files
committed
fix(config): add persistance mode
fixes #15102
1 parent f032769 commit db0049f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

core/src/global/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IonicConfig {
66
* Possible values are: `"ios"` or `"md"`.
77
*/
88
mode?: Mode;
9+
_persist?: boolean;
910

1011
isDevice?: boolean;
1112
statusbarPadding?: boolean;

core/src/global/ionic-global.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'ionicons';
22

3-
import { configFromURL } from '../utils/config';
3+
import { configFromSession, configFromURL, saveConfig } from '../utils/config';
44
import { isIOS } from '../utils/platform';
55

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

1717
// create the Ionic.config from raw config object (if it exists)
1818
// and convert Ionic.config into a ConfigApi that has a get() fn
19-
const config = Ionic['config'] = Context['config'] = new Config({
19+
const configObj = {
2020
...Ionic['config'],
21+
...configFromSession(),
2122
...configFromURL()
22-
});
23+
};
24+
const config = Ionic['config'] = Context['config'] = new Config(configObj);
25+
if (config.getBoolean('_persist', false)) {
26+
saveConfig(configObj);
27+
}
2328

2429
// first see if the mode was set as an attribute on <html>
2530
// which could have been set by the user, or by prerendering

core/src/utils/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export function setupConfig(config: IonicConfig) {
1616
}
1717

1818
const IONIC_PREFIX = 'ionic:';
19+
const IONIC_SESSION_KEY = 'ionic-persist-config';
20+
21+
export function configFromSession(): any {
22+
const configStr = window.sessionStorage.getItem(IONIC_SESSION_KEY);
23+
return configStr ? JSON.parse(configStr) : {};
24+
}
25+
26+
export function saveConfig(config: any) {
27+
window.sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(config));
28+
}
1929

2030
export function configFromURL() {
2131
const config: any = {};

0 commit comments

Comments
 (0)