If the state type generic contains an optional property and that property is correctly omitted from the initial state in the constructor, the property never gets set afterwards even when consumers attempt to do so.
Example component:
import {html, render as litRender} from 'lit-html';
import {ReduxularElement} from '../../reduxular-element';
type State = {
// NOTE: this is optional!
optionalCount?: number;
};
// This initial state is valid!
const initialState: Readonly<State> = {};
class ReduxularElementTestOptionalProperty extends ReduxularElement<State> {
constructor() {
super(initialState, state => {
litRender(this.render(state), this);
});
}
render(state: Readonly<State>) {
console.log('reduxular-element-test-optional-property:', state.optionalCount);
return html`
<div>reduxular-element-test-optional-property: ${state.optionalCount}</div>
`;
}
}
window.customElements.define('reduxular-element-test-optional-property', ReduxularElementTestOptionalProperty);
To see in action add the following to reduxular-app.ts
's render method output:
<reduxular-element-test-optional-property .optionalCount=${state.count}></reduxular-element-test-optional-property>
Notice that the count value of reduxular-element-test-optional-property
never updates.