/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ // @flow /** * When Flow 0.29 is released (very soon), we can use this Record type * instead of the builtin immutable.js Record type. This is better * because all the fields are actually typed, unlike the builtin one. * This depends on a performance fix that will go out in 0.29 though; * @module utils/makeRecord */ import * as I from "immutable"; /** * @memberof utils/makeRecord * @static */ export type Record = { equals(other: A): boolean, get(key: $Keys, notSetValue?: any): A, getIn(keyPath: Array, notSetValue?: any): A, hasIn(keyPath: Array): boolean, set(key: $Keys, value: A): Record, setIn(keyPath: Array, ...iterables: Array): Record, merge(values: $Shape): Record, mergeIn(keyPath: Array, ...iterables: Array): Record, delete(key: $Keys, value: A): Record, deleteIn(keyPath: Array, ...iterables: Array): Record, update(key: $Keys, value: A): Record, updateIn(keyPath: Array, ...iterables: Array): Record, remove(key: $Keys): Record, toJS(): T } & T; /** * Make an immutable record type * * @param spec - the keys and their default values * @return a state record factory function * @memberof utils/makeRecord * @static */ function makeRecord(spec: T & Object): (init: $Shape) => Record { return I.Record(spec); } export default makeRecord;