Class Bundle<R>

To make bulk updates to multiple instances of a resource, use the Bundle class. A bundle can be created with a list of instance ids and a factory function that creates a new instance of the resource with the given id. Alternatively, a bundle can be created with a list of instances. In order to make changes to the instances, the bundle object should be used as a proxy object. This will track all changes made to the object and mirror them on the instances. When the update method is called, all changes will be sent to the API to update the instances.

Example

const bundle = new Bundle<Story>({ids: [1, 2, 3]}, (data) => new Story(data))
bundle.estimate = 3
bundle.update() // Changes are propagated to the instances and sent to the API

Type Parameters

Indexable

[key: string]: ShortcutFieldType

Constructors

  • Create a new Bundle object

    Type Parameters

    Parameters

    • bundled: (string | number)[] | R[]

      Either a list of instance ids or a list of instances

    • Optional factory: ((data) => R)

      A function that creates a new instance of the resource with the given id, required if bundled is a list of ids

        • (data): R
        • Parameters

          • data: {
                id: string | number;
            }
            • id: string | number

          Returns R

    Returns Bundle<R>

    Example

    const bundle = new Bundle<Story>([1, 2, 3], (data) => new Story(data))
    const otherBundle = new Bundle<Story>([new Story({id: 1}), new Story({id: 2})])

Properties

changedFields: string[] = []
factory: ((data) => R)

Type declaration

    • (data): R
    • Parameters

      • data: {
            id: string | number;
        }
        • id: string | number

      Returns R

id?: null | string | number
instanceIds: string[] | number[] = []
resources: BaseResource<default>[]

Methods

  • Returns Promise<void>