componentDidMount() {
// Get element to attach the table from the DOM.
const elem = (document.getElementsByTagName("perspective-viewer")[0] as unknown) as PerspectiveViewerElement;
if (window.perspective && window.perspective.worker()) {
this.table = window.perspective.worker().table(schema);
}
if (this.table) {
// Load the table in the <perspective-viewer> DOM reference.
componentDidUpdate() {
// Everytime the data props is updated, insert the data into Perspective table
if (this.table) {
// As part of the task, you need to fix the way we update the data props to
// avoid inserting duplicated entries into Perspective table again.
this.table.update(
this.props.data.map((el: any) => {
// Format the data from ServerRespond to the schema
return {
stock: el.stock,
top_ask_price: (el.top_ask && el.top_ask.price) || 0,
top_bid_price: (el.top_bid && el.top_bid.price) || 0,
timestamp: el.timestamp,
};
})
);
}
}
}
export default Graph;
And I'm receiving the error message:
Parsing error: Unexpected token, expected ","
Here is my code:
import React, { Component } from "react"; import { Table } from "@finos/perspective"; import { ServerRespond } from "./DataStreamer"; import "./Graph.css";
/**
/**
/**
parsed from its parent through data property. */ class Graph extends Component<IProps, {}> { // Perspective table table: Table | undefined;
render() { return React.createElement("perspective-viewer"); }
componentDidMount() { // Get element to attach the table from the DOM. const elem = (document.getElementsByTagName("perspective-viewer")[0] as unknown) as PerspectiveViewerElement;
const schema = { stock: "string", top_ask_price: "float", top_bid_price: "float", timestamp: "date", };
if (window.perspective && window.perspective.worker()) { this.table = window.perspective.worker().table(schema); } if (this.table) { // Load the
table
in the<perspective-viewer>
DOM reference.// Add more Perspective configurations here. elem.load(this.table); elem.setAttribute("view", "y-line"); elem.setAttribute("column-pivots", '["stock"]'); elem.setAttribute("row-pivots", '["timestamp"]'); elem.setAttribute("columns", '["top-ask-price"]'); elem.setAttribute( "aggregates",
{"stock":"distinct count", "top-ask-price": "avg", "top-bid-price": "avg", "timestamp": "distinct count"}
); } }componentDidUpdate() { // Everytime the data props is updated, insert the data into Perspective table if (this.table) { // As part of the task, you need to fix the way we update the data props to // avoid inserting duplicated entries into Perspective table again. this.table.update( this.props.data.map((el: any) => { // Format the data from ServerRespond to the schema return { stock: el.stock, top_ask_price: (el.top_ask && el.top_ask.price) || 0, top_bid_price: (el.top_bid && el.top_bid.price) || 0, timestamp: el.timestamp, }; }) ); } } }
export default Graph;
And I'm receiving the error message: Parsing error: Unexpected token, expected ","
35 | const elem = (document.getElementsByTagName( 36 | "perspective-viewer" > 37 | )[0] as unknown) as PerspectiveViewerElement; | ^ 38 | 39 | const schema = { 40 | stock: "string",
And it does not have to do with the parentheses around ocuments.get...