Skip to content

Commit

Permalink
Rename deleteStateOnWindowLoad to deleteOnClientLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
codinronan committed Jun 12, 2018
1 parent ab94b85 commit 64bfb4b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ declare global {

namespace StencilComponents {
interface StencilLift {
'deleteStateOnWindowLoad': boolean;
'deleteOnClientLoad': boolean;
'initialState': any;
'mergeState': boolean;
}
Expand All @@ -155,7 +155,7 @@ declare global {
}
namespace JSXElements {
export interface StencilLiftAttributes extends HTMLAttributes {
'deleteStateOnWindowLoad'?: boolean;
'deleteOnClientLoad'?: boolean;
'initialState'?: any;
'mergeState'?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/example/example-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ExampleApp {

render() {
const liftProps = {
deleteStateOnWindowLoad: false,
deleteOnClientLoad: false,
initialState,
mergeState: true,
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/stencil-lift/stencil-lift.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ClientLiftService, { LiftService, __LIFT_STATE_KEY } from '../../services
})
export class StencilLiftComponent {

@Prop() deleteStateOnWindowLoad = false;
@Prop() deleteOnClientLoad = false;
@Prop() initialState: any = null;
@Prop() mergeState = false;

Expand All @@ -26,7 +26,7 @@ export class StencilLiftComponent {
this._LiftService.initialize({
win: this.window,
isServer: this.isServer,
deleteStateOnWindowLoad: this.deleteStateOnWindowLoad,
deleteOnClientLoad: this.deleteOnClientLoad,
initialState: this.initialState,
mergeState: this.mergeState,
});
Expand Down
10 changes: 7 additions & 3 deletions src/services/lift.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const combinedReducers = combineReducers({ lift_state: liftReducer });
export interface LiftInitializeOptions {
win: Window;
isServer: boolean;
deleteStateOnWindowLoad: boolean;
deleteOnClientLoad: boolean;
initialState: any;
mergeState: boolean;
}
Expand Down Expand Up @@ -57,11 +57,15 @@ export class LiftService {
}

initialize(options: LiftInitializeOptions) {
const { isServer, deleteStateOnWindowLoad, initialState, mergeState, win } = options;
const { isServer, deleteOnClientLoad, initialState, mergeState, win } = options;
this._isServer = isServer;

let preloadedState = (<any>win)[__LIFT_STATE_KEY] || {};
deleteStateOnWindowLoad && (delete (<any>win)[__LIFT_STATE_KEY]);
if (deleteOnClientLoad && !this.isServer && document) {
const elm = document.querySelector(`#${__LIFT_STATE_KEY}`);
if (elm) { elm.remove(); } // Stencil polyfills this so it is ok.
delete (<any>win)[__LIFT_STATE_KEY];
}

if (initialState) {
preloadedState = mergeState ? { ...preloadedState, ...initialState } : initialState || {};
Expand Down
4 changes: 3 additions & 1 deletion stencil.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ exports.config = {
enableCache: false,
namespace: 'stencil-lift',
flags: { prerender: true },
logLevel: 'debug',
buildEs5: true,
buildStats: true,
logLevel: 'debug', // do not turn this off until the Stencil bug is fixed.
outputTargets:[
{
type: 'dist'
Expand Down

0 comments on commit 64bfb4b

Please sign in to comment.