os-js / osjs-gui

OS.js GUI Module

Home Page:https://manual.os-js.org/v3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ListView helper actions

andersevenrud opened this issue · comments

This came up in a conversation on Gitter. The ListView does not have any methods to manipulate rows, only set them ( setRows()).

Solution:

    addRow: row => state => ({rows: [...state.rows, row]}),
    removeRowByIndex: index => state => {
      const rows = state.rows;
      if (index >= 0) {
        rows.splice(index, 1)
      }
      return {rows}
    },
    removeRow: row => (state, actions) => {
      const foundIndex = rows.findIndex(r => r === row);
      return actions.removeRowByIndex(foundIndex);
    }