@mantlebee/ts-data
    Preparing search index...

    Function createDataSource

    • Builds a data source whose type carries its extensions: the record given here, key by key (IDataSource). It is the way to build a source: the DataSource class behind it cannot type its members from a generic record, so new DataSource(reader, { filtering }) exposes no key in its type. The class is exported to be extended, by a subclass that declares its keys.

      The extensions run in the order of the keys of the record, the order you write them in: filtering before pagination, so the count reader receives the filters.

      Type Parameters

      Parameters

      • reader: DataSourceReader<TItem>

        Resolves the payload into the items; receives the signal of the read as second argument.

      • extensions: TExt

        Extensions by key, run in this order; {} for none.

      Returns IDataSource<TItem, TExt>

      the data source, typed with the extensions of the record.

      const users = createDataSource(readUsers, { filtering, pagination, distinct });
      // IDataSource<User, { filtering: FilterExtension<User>; pagination: PaginationExtension<User>; distinct: DistinctExtension<User> }>
      users.filtering.addFilter(adult);
      users.distinct; // a custom key, typed

      const maybeSorting: SortExtension<User> | undefined = options.sortable
      ? new SortExtension<User>()
      : undefined;
      const products = createDataSource(readProducts, { filtering, sorting: maybeSorting });
      products.sorting; // SortExtension<User> | undefined: a value that may be undefined is optional