Skip to content

Commit

Permalink
Update renderer handlers when element is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
poffdeluxe committed Oct 27, 2020
1 parent 0793089 commit 5b10096
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { getType } from '@kbn/interpreter/common';
import { Loading } from '../loading';
import { RenderWithFn } from '../render_with_fn';
import { ElementShareContainer } from '../element_share_container';
import { assignHandlers } from '../../lib/create_handlers';
import { InvalidExpression } from './invalid_expression';
import { InvalidElementType } from './invalid_element_type';

Expand Down Expand Up @@ -48,15 +47,7 @@ export const ElementContent = compose(
pure,
...branches
)(({ renderable, renderFunction, width, height, handlers }) => {
const {
getFilter,
setFilter,
done,
onComplete,
onEmbeddableInputChange,
onEmbeddableDestroyed,
getElementId,
} = handlers;
const { onComplete } = handlers;

return Style.it(
renderable.css,
Expand All @@ -79,14 +70,7 @@ export const ElementContent = compose(
css={renderable.css} // This is an actual CSS stylesheet string, it will be scoped by RenderElement
width={width}
height={height}
handlers={assignHandlers({
getFilter,
setFilter,
done,
onEmbeddableInputChange,
onEmbeddableDestroyed,
getElementId,
})}
handlers={handlers}
/>
</ElementShareContainer>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import React, { useState, useEffect, useRef, FC, useCallback } from 'react';

import { isEqual } from 'lodash';

import { useNotifyService } from '../../services';
import { RenderToDom } from '../render_to_dom';
import { ErrorStrings } from '../../../i18n';
Expand Down Expand Up @@ -81,6 +83,12 @@ export const RenderWithFn: FC<Props> = ({
[]
);

useEffect(() => {
if (!isEqual(handlers.current, incomingHandlers)) {
handlers.current = incomingHandlers;
}
}, [incomingHandlers]);

const render = useCallback(() => {
renderFn(renderTarget.current!, config, handlers.current);
}, [renderTarget, config, renderFn]);
Expand Down

0 comments on commit 5b10096

Please sign in to comment.