Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace models

Provides utilities for working with collections of structured data. Simplifies and standardizes support for common UI and business logic surrounding data collections. You can easily extend functionality by combining existing wrappers or by writing your own.

// esm
import { models } from '@paychex/core';

// cjs
const { models } = require('@paychex/core');

// iife
const { models } = window['@paychex/core'];

// amd
require(['@paychex/core'], function({ models }) { ... });
define(['@paychex/core'], function({ models }) { ... });
example
import { createRequest, fetch } from '~/path/to/data';

const getUserReports = {
method: 'GET',
base: 'reporting',
path: 'reports/:user',
};

export async function getReports(user) {
const request = createRequest(getUserReports, { user });
const response = await fetch(request);
const reportList = models.collection(...response.data);
// order reports newest first and then by name
return models.utils.withOrdering(reportList, ['date', 'name'], ['desc', 'asc']);
}

Index

Namespaces

Interfaces

Variables

Functions

Variables

Events: models.EventCollection = ...

Functions

  • Creates a new ModelCollection instance.

    example
    export const emptyModel = models.collection();
    export const filledModel = models.collection(1, 2, 3);
    example
    import { createRequest, fetch } from '~/path/to/data';
    import { loadClientData } from '../data';

    export async function createClientDataModel(client) {
    const request = createRequest(loadClientData, { client });
    const response = await fetch(request);
    return models.collection(...response.data); // spread values
    }

    Parameters

    • Rest ...elements: any[]

    Returns ModelCollection

    A new ModelCollection instance