• dataFactoryFor(defaultObject)

    Returns a new factory function that returns can be called to obtain a copy of defaultObject. Optionally, the factory function can be passed a partialObject in which case it will return a copy of the merged object.

    Any properties appearing in partialObject must be complete objects. If you want to update a deeply nested property by itself, you can do so by directly modifying the object. This is safe because

    This can still be a bit awkward since there may be a number of optionals that you have to check before setting the value.

    Example (shallow override):

        const BASE_OBJECT = {
    student: { ... },
    teacher: { ... },
    };
    const dataFactory = dataFactoryFor(BASE_OBJECT);
    const data = dataFactory({
    student: {
    __typename: "User",
    id: "new_kaid",
    kaid: "new_kaid",
    ... other properties on `user`
    }
    });

    Example (deep update):

        const BASE_OBJECT = {
    student: { ... },
    teacher: { ... },
    };
    const dataFactory = dataFactoryFor(BASE_OBJECT);
    const data = dataFactory();
    if (data.user) {
    data.user.kaid = "new_kaid";
    data.user.id = "new_kaid";
    }

    Type Parameters

    • T

    Parameters

    • baseObject: T

    Returns ((partialObject?) => T)

      • (partialObject?): T
      • Parameters

        • Optional partialObject: Partial<T>

        Returns T

Generated using TypeDoc