Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render() {
const { refreshing, pressed } = this.state;
const { element, stylesheets, onUpdate, options } = this.props;
const behaviorElements = getBehaviorElements(element);
const pressBehaviors = behaviorElements.filter(
e =>
PRESS_TRIGGERS.indexOf(
e.getAttribute(ATTRIBUTES.TRIGGER) || TRIGGERS.PRESS,
) >= 0,
);
const visibleBehaviors = behaviorElements.filter(
e => e.getAttribute(ATTRIBUTES.TRIGGER) === TRIGGERS.VISIBLE,
);
const refreshBehaviors = behaviorElements.filter(
e => e.getAttribute(ATTRIBUTES.TRIGGER) === TRIGGERS.REFRESH,
);
// Render the component based on the XML element. Depending on the applied behaviors,
// this component will be wrapped with others to provide the necessary interaction.
let renderedComponent = Render.renderElement(
refresh = () => {
const { element, onUpdate } = this.props;
this.setState({ refreshing: true });
getBehaviorElements(element)
.filter(e => e.getAttribute('trigger') === 'refresh')
.forEach((e, i) => {
const path = e.getAttribute('href');
const action = e.getAttribute('action') || 'append';
const targetId = e.getAttribute('target');
const showIndicatorIds = e.getAttribute('show-during-load');
const hideIndicatorIds = e.getAttribute('hide-during-load');
const delay = e.getAttribute('delay');
const once = e.getAttribute('once');
const onEnd =
i === 0 ? () => this.setState({ refreshing: false }) : null;
onUpdate(path, action, element, {
targetId,
showIndicatorIds,
hideIndicatorIds,
delay,
triggerLoadBehaviors = () => {
const behaviorElements = getBehaviorElements(this.props.element);
const loadBehaviors = behaviorElements.filter(
e => e.getAttribute(ATTRIBUTES.TRIGGER) === TRIGGERS.LOAD,
);
loadBehaviors.forEach(behaviorElement => {
const handler = this.createActionHandler(
this.props.element,
behaviorElement,
this.props.onUpdate,
);
setTimeout(handler, 0);
});
};
triggerSelectBehaviors = () => {
const { element, onUpdate } = this.props;
const behaviorElements = getBehaviorElements(element);
const selectBehaviors = behaviorElements.filter(
e => e.getAttribute('trigger') === 'select',
);
selectBehaviors.forEach(behaviorElement => {
const href = behaviorElement.getAttribute('href');
const action = behaviorElement.getAttribute('action');
const verb = behaviorElement.getAttribute('verb');
const targetId = behaviorElement.getAttribute('target');
const showIndicatorIds = behaviorElement.getAttribute('show-during-load');
const hideIndicatorIds = behaviorElement.getAttribute('hide-during-load');
const delay = behaviorElement.getAttribute('delay');
const once = behaviorElement.getAttribute('once');
onUpdate(href, action, element, {
verb,
targetId,
showIndicatorIds,