-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix-page-clone
- Loading branch information
Showing
20 changed files
with
959 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/core/src/data_sources/model/conditional_variables/ConditionalComponent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Component from '../../../dom_components/model/Component'; | ||
import Components from '../../../dom_components/model/Components'; | ||
import { ComponentDefinition, ComponentOptions } from '../../../dom_components/model/types'; | ||
import { toLowerCase } from '../../../utils/mixins'; | ||
import { DataCondition, ConditionalVariableType, Expression, LogicGroup } from './DataCondition'; | ||
|
||
type ConditionalComponentDefinition = { | ||
condition: Expression | LogicGroup | boolean; | ||
ifTrue: any; | ||
ifFalse: any; | ||
}; | ||
|
||
export default class ComponentConditionalVariable extends Component { | ||
dataCondition: DataCondition; | ||
componentDefinition: ConditionalComponentDefinition; | ||
|
||
constructor(componentDefinition: ConditionalComponentDefinition, opt: ComponentOptions) { | ||
const { condition, ifTrue, ifFalse } = componentDefinition; | ||
const dataConditionInstance = new DataCondition(condition, ifTrue, ifFalse, { em: opt.em }); | ||
const initialComponentsProps = dataConditionInstance.getDataValue(); | ||
const conditionalCmptDef = { | ||
type: ConditionalVariableType, | ||
components: initialComponentsProps, | ||
}; | ||
super(conditionalCmptDef, opt); | ||
|
||
this.componentDefinition = componentDefinition; | ||
this.dataCondition = dataConditionInstance; | ||
this.dataCondition.onValueChange = this.handleConditionChange.bind(this); | ||
} | ||
|
||
private handleConditionChange() { | ||
this.dataCondition.reevaluate(); | ||
const updatedComponents = this.dataCondition.getDataValue(); | ||
this.components().reset(); | ||
this.components().add(updatedComponents); | ||
} | ||
|
||
static isComponent(el: HTMLElement) { | ||
return toLowerCase(el.tagName) === ConditionalVariableType; | ||
} | ||
|
||
toJSON(): ComponentDefinition { | ||
return this.dataCondition.toJSON(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import ComponentView from '../../dom_components/view/ComponentView'; | ||
import ConditionalComponent from '../model/conditional_variables/ConditionalComponent'; | ||
|
||
export default class ConditionalComponentView extends ComponentView<ConditionalComponent> {} |
Oops, something went wrong.