How to use the solid-js.createState function in solid-js

To help you get started, we’ve selected a few solid-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bluenote10 / tabloo / src_frontend / PlotHandler.tsx View on Github external
function PlotWrapper(props: PlotWrapperProps) {
  let el: HTMLDivElement = null!;
  let chart: ECharts = null!;

  const [state, setState] = createState({
    mounted: false,
    cachedPlotData: null,
  })

  let updatePlot = (plotData: any) => {
    if (chart == null) {
      chart = echarts.init(el as HTMLDivElement);
    }
    console.log("updating plot with:", plotData)
    chart.setOption(plotData)
  }

  createEffect(() => {
    // effect to monitor changes to props.plotData
    let newPlotData = props.plotData;
    if (sample(() => state.mounted)) {
github bluenote10 / tabloo / src_frontend / TableHandler.tsx View on Github external
function Table(props: {
    data: TableData,
    cbSort: (sortKind: number, columnIndex?: number) => void,
  }) {

  const [state, setState] = createState({
    rowsData: [] as Value[][],
    headerData: [] as ColHeader[],
    sortColIndex: undefined as (number | undefined),
    sortColKind: 0,
  })

  let columnFormatters = [] as ColumnFormatter[];

  createEffect(() => {
    console.log("Data updated", props.data.length)
    const data = props.data
    if (data.length == 0) {
      return;
    }

    // update column formatters
github bluenote10 / tabloo / src_frontend / PlotHandler.tsx View on Github external
export function PlotHandler(props: {
    store: StoreInterface,
    filter: string,
    onSetFilter: (s: string) => void,
  }) {

  const { store } = props

  /*
  const dataFetchOptions = {
    sortKind: 0,
  } as DataFetchOptions
  */

  const [state, setState] = createState({
    columns: [] as string[],
    plotData: {} as any,
    selectedColX: undefined! as number,
    selectedColY: undefined! as number,
  })

  createEffect(() => {
    // handels updates of selected column indices
    let xCol = state.selectedColX;
    let yCol = state.selectedColY;
    let filter = props.filter;
    if (xCol != undefined && yCol != undefined) {
      fetchData(xCol, yCol, filter);
    }
  })
github bluenote10 / tabloo / src_frontend / MapHandler.tsx View on Github external
export function MapHandler(props: {
    store: StoreInterface,
    filter: string,
    onSetFilter: (s: string) => void,
  }) {

  const { store } = props

  const [state, setState] = createState({
    columns: [] as string[],
    mapData: {} as any,
    selectedCol: undefined! as number,
  })

  createEffect(() => {
    // handels updates of selected column indices
    let col = state.selectedCol;
    let filter = props.filter;
    if (col != undefined) {
      fetchData(col, filter);
    }
  })

  async function fetchColumns() {
    let columns = await store.fetchColumns()
github bluenote10 / tabloo / src_frontend / Dropdown.tsx View on Github external
export function Dropdown(props: DropdownProps) {

  const [state, setState] = createState({
    active: false,
  })

  function onClick(event: Event) {
    setState({active: !state.active})
  }
  function onBlur(event: Event) {
    setState({active: false})
  }

  // Note the click handler of the dropdown items uses an onMouseDown
  // so that the onBlur of the menu expansion isn't handled before the
  // onClick of the item, see:
  // https://stackoverflow.com/questions/17769005/onclick-and-onblur-ordering-issue
  return (
    <div class="{(&quot;dropdown&quot;"></div>
github bluenote10 / tabloo / src_frontend / MapHandler.tsx View on Github external
function MapWrapper(props: {
    mapData?: any,
  }) {

  let el: HTMLDivElement = null!;
  let map: leaflet.Map | undefined = undefined;
  let layerGroup: leaflet.LayerGroup | undefined = undefined;

  const [state, setState] = createState({
    mounted: false,
    cachedMapData: null,
  })

  let updateMap = (mapData: any) =&gt; {
    if (map == null) {
      console.log("Init map", el);
      map = leaflet.map(el, {preferCanvas: true}).fitWorld();
      leaflet.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
        attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
      }).addTo(map)
    }


    let t1 = performance.now()
    if (false) {
github bluenote10 / tabloo / src_frontend / TableHandler.tsx View on Github external
export function TableHandler(props: {
    store: StoreInterface,
    filter: string,
    onSetFilter: (s: string) => void,
  }) {

  const { store } = props

  const [state, setState] = createState({
    tableData: [] as TableData,
    sortKind: 0,
    sortColumn: undefined as (string|undefined),
    pagination: {
      numPages: 0,
      currentPage: 0
    } as PaginationData
  })

  initialize()

  async function initialize() {
    await fetchNumPages()
    await fetchData()
  }
github bluenote10 / tabloo / src_frontend / App.tsx View on Github external
export function App({store} : {store: StoreInterface}) {

  const [state, setState] = createState({
    appstate: {
      tabs: [
        {
          name: {
            icon: "database",
            text: "Table",
          },
          widgets: [
            {
              type: "table",
              filterId: "default",
            },
          ]
        },
        {
          name: {

solid-js

A declarative JavaScript library for building user interfaces.

MIT
Latest version published 1 month ago

Package Health Score

94 / 100
Full package analysis