(props: Props)
| 31 | } |
| 32 | |
| 33 | function _SandDanceReact(props: Props) { |
| 34 | |
| 35 | class __SandDanceReact extends base.react.Component<Props, State> { |
| 36 | public viewer: Viewer; |
| 37 | private viewerDiv: React.ReactInstance; |
| 38 | private lastData: object[]; |
| 39 | |
| 40 | private layout() { |
| 41 | this.lastData = this.props.data; |
| 42 | this.viewer.render( |
| 43 | this.props.insight, |
| 44 | this.props.data, |
| 45 | this.props.renderOptions, |
| 46 | ).then(renderResult => { |
| 47 | //TODO: show errors if any |
| 48 | //console.log('viewer render'); |
| 49 | this.props.onView && this.props.onView(renderResult); |
| 50 | }).catch(e => { |
| 51 | //console.log('viewer error'); |
| 52 | this.props.onError && this.props.onError(e); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | private view() { |
| 57 | if (this.props.insight && this.props.data) { |
| 58 | const c = compareProps(this.viewer, this.props.insight); |
| 59 | const sameDataRef = this.props.data === this.lastData; |
| 60 | if (!c.compare || !sameDataRef) { |
| 61 | this.layout(); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | componentDidMount() { |
| 67 | const element = base.reactDOM.findDOMNode(this.viewerDiv) as HTMLElement; |
| 68 | this.viewer = new Viewer(element, this.props.viewerOptions); |
| 69 | if (this.props.onMount) { |
| 70 | if (this.props.onMount(this.viewer.presenter.getElement(VegaDeckGl.PresenterElement.gl))) { |
| 71 | this.view(); |
| 72 | } |
| 73 | } else { |
| 74 | this.view(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | componentDidUpdate() { |
| 79 | this.viewer.options = VegaDeckGl.util.deepMerge(this.viewer.options, this.props.viewerOptions) as types.ViewerOptions; |
| 80 | this.view(); |
| 81 | } |
| 82 | |
| 83 | componentWillUnmount() { |
| 84 | this.viewer.finalize(); |
| 85 | } |
| 86 | |
| 87 | render() { |
| 88 | return ( |
| 89 | <div className="sanddance-ReactViewer" ref={div => (this.viewerDiv = div)} /> |
| 90 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected