immutable#Record TypeScript Examples

The following examples show how to use immutable#Record. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
UserRecordState = Record({
  userGroupList: {},
  updateUser: {},
  userList: {},
  userpagination: {},
  newUser: {},

  listLoading: false,
  listLoaded: false,
  listFailed: false,

  countLoading: false,
  countLoaded: false,
  countFailed: false,

  addLoading: false,
  addLoaded: false,
  addFailed: false,

  updatLoading: false,
  updatLoaded: false,
  updatFailed: false,

  updateLoading: false,
  updateLoaded: false,
  updateFailed: false,

  userGroupLoading: false,
  userGroupLoaded: false,
  userGroupFailed: false,
  userDelate: {}
})
Example #2
Source File: scopeUpdaterValues.ts    From ui-schema with MIT License 6 votes vote down vote up
scopeUpdaterValues = <S extends UIStoreType = UIStoreType, A extends UIStoreActions = UIStoreActions>(
    store: S, storeKeys: StoreKeys, newValue: any, action: A,
): S => {
    //if (typeof oldValue === 'undefined') {
    // initializing the tree for correct data types
    // https://github.com/ui-schema/ui-schema/issues/119
    store = storeBuildScopeTree(storeKeys, 'values', store, undefined, true)
    //}
    // todo: the decision for `should delete` should only come from "value", and then used by e.g. internalValue/validity updates,
    //       but also some internal values must be preserved, like `is default handled`, `richtext editor state`
    // todo: also, actually, it must be checked & deleted recursively
    if (shouldDeleteOnEmpty(newValue, action?.schema?.get('deleteOnEmpty') as boolean || action?.required, action?.schema?.get('type') as SchemaTypesType)) {
        if (storeKeys.size) {
            const parentStore = store.getIn(prependKey(storeKeys.splice(storeKeys.size - 1, 1) as StoreKeys, 'values'))
            // e.g. numbers in tuples must only be deleted, when it is inside an object, when inside an `list` undefined must be used for a "reset"
            // todo: support valueOnDelete and fix behaviour in Array tuples https://github.com/ui-schema/ui-schema/issues/106
            //       also tests are missing atm.
            if (List.isList(parentStore)) {
                store = store.setIn(prependKey(storeKeys, 'values'), null)
            } else if (Map.isMap(parentStore) || Record.isRecord(parentStore)) {
                store = store.deleteIn(prependKey(storeKeys, 'values'))
            }
        } else {
            store = store.deleteIn(['values'])
        }
        return store
    }

    // todo: when parent is a `list`, check if "all other array items exist" - and when not, fill them with e.g. `null`

    return updateStoreScope(
        store, 'values', storeKeys,
        newValue
    )
}
Example #3
Source File: options.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/**
 * The plugin options
 */
class Options
  extends Record({
    onlyIn: defaultOnlyIn,
    getSyntax: defaultGetSyntax,
    renderDecoration: defaultRenderDecoration,
  })
  implements OptionsFormat {
  readonly onlyIn!: (node: Node) => boolean;
  readonly getSyntax!: (node: Node) => string;
  readonly renderDecoration!: (
    {
      decoration,
      children,
    }: {
      decoration: Decoration;
      children: React.ReactNode;
    },
    editor: Editor,
    next: () => any
  ) => void | React.ReactNode;

  constructor(props: OptionsFormat) {
    super(props);
  }
}
Example #4
Source File: incomingTransaction.ts    From multisig-react with MIT License 6 votes vote down vote up
makeIncomingTransaction = Record({
  blockNumber: 0,
  executionTxHash: '',
  safeTxHash: '',
  to: '',
  value: 0,
  tokenAddress: '',
  from: '',
  symbol: '',
  decimals: 18,
  fee: '',
  executionDate: '',
  type: 'INCOMING',
  status: 'success',
  nonce: null,
  confirmations: null,
  recipient: null,
  data: null,
  operation: null,
  safeTxGas: null,
  baseGas: null,
  gasPrice: null,
  gasToken: null,
  refundReceiver: null,
  isExecuted: null,
  submissionDate: null,
  executor: null,
  cancelled: null,
  modifySettingsTx: null,
  cancellationTx: null,
  customTx: null,
  creationTx: null,
  isTokenTransfer: null,
  decodedParams: null,
  refundParams: null,
})
Example #5
Source File: zone.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
ZoneRecordState = Record({
  zoneList: {},
  newZone: {},
  updateZone: {},
  zoneDelete: {},
  zonePagination: {},

  listLoading: false,
  listLoaded: false,
  listFailed: false,

  countLoading: false,
  countLoaded: false,
  countFailed: false,

  addLoading: false,
  addLoaded: false,
  addFailed: false,

  updateLoading: false,
  updateLoaded: false,
  updateFailed: false,

  deleteLoading: false,
  deleteLoaded: false,
  deleteFailed: false
})
Example #6
Source File: safe.ts    From multisig-react with MIT License 6 votes vote down vote up
makeSafe = Record<SafeRecordProps>({
  name: '',
  address: '',
  threshold: 0,
  ethBalance: '0',
  owners: List([]),
  modules: [],
  spendingLimits: [],
  activeTokens: Set(),
  activeAssets: Set(),
  blacklistedTokens: Set(),
  blacklistedAssets: Set(),
  balances: Map(),
  nonce: 0,
  latestIncomingTxBlock: 0,
  recurringUser: undefined,
  currentVersion: '',
  needsUpdate: false,
  featuresEnabled: [],
})
Example #7
Source File: product-control.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
productControlRecord = Record({
  wishlist: [],
  cartList: [],
  cartCount: [],
  totalCartPrice: [],
  checkedOut: [],

  checkoutLoading: false,
  checkoutLoaded: false,
  checkoutFailed: false,
  whislistLoading: false

})
Example #8
Source File: provider.ts    From multisig-react with MIT License 6 votes vote down vote up
makeProvider = Record<ProviderProps>({
  name: '',
  loaded: false,
  available: false,
  account: '',
  network: HARMONY_NETWORK.UNKNOWN,
  smartContractWallet: false,
  hardwareWallet: false,
})
Example #9
Source File: customer.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
CustomerStateRecord = Record({
  customerList: {},
  pagination: {},
  addcustomer: {},
  updatecustomer: {},
  deletecustomer: {},
  detailCustomer: {},

  detailLoading: false,
  detailLoaded: false,
  detailFailed: false,
  listLoading: false,
  listLoaded: false,
  listFailed: false,

  countLoading: false,
  countLoaded: false,
  countFailed: false,

  addLoading: false,
  addLoaded: false,
  addFailed: false,

  updateLoading: false,
  updateLoaded: false,
  updateFailed: false,

  deleteLoading: false,
  deleteLoaded: false,
  deleteFailed: false,

  customersGroupListLoading: false,
  customersGroupListLoaded: false,
  customersGroupListFailed: false,
  customersGroupList: []
})
Example #10
Source File: UIStorePro.ts    From ui-schema with MIT License 5 votes vote down vote up
UIStoreProRecord = Record({
    activeIndex: 0,
    current: createEmptyStore('object'),
    list: List([createEmptyStore('object')]),
    opts: Map(),
} as UIStoreProData)
Example #11
Source File: generalsetting.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
GeneralsettingRecordState = Record({
  newgeneralsettings: {},
  getgeneralsetting: {}
})
Example #12
Source File: currencyValues.ts    From multisig-react with MIT License 5 votes vote down vote up
makeBalanceCurrency = Record<BalanceCurrencyRecord>({
  currencyName: '',
  tokenAddress: '',
  balanceInBaseCurrency: '',
  balanceInSelectedCurrency: '',
})
Example #13
Source File: product.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
ProductStateRecord = Record({
  productlist: [],
  productCount: 0,
  productDelete: {},
  productAdded: {},
  productUpdate: {},
  productDetail: {},
  gettingoptionList: {},
  productBulkDelete: {},

  detailLoading: false,
  detailLoaded: false,
  detailFailed: false,

  listLoading: false,
  listLoaded: false,
  listFailed: false,

  countLoading: false,
  countLoaded: false,
  countFailed: false,

  addLoading: false,
  addLoaded: false,
  addFailed: false,

  updatLoading: false,
  updatLoaded: false,
  updatFailed: false,

  updateLoading: false,
  updateLoaded: false,
  updateFailed: false,

  deleteLoading: false,
  deleteLoaded: false,
  deleteFailed: false,

  gettingOptionLoading: false,
  gettingOptionLoaded: false,
  gettingOptionFailed: false
})
Example #14
Source File: World.ts    From compound-protocol with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
export class World extends Record(defaultWorldProps) {
  public readonly actions!: Action<any>[];
  public readonly event!: Event | null;
  public readonly value!: number | null;
  public readonly lastInvokation!: Invokation<any> | null;
  public readonly newInvokation!: boolean;
  public readonly blockNumber!: number;
  public readonly gasCounter!: Counter;
  public readonly lastContract!: Contract | null;
  public readonly invariants!: Invariant[];
  public readonly expectations!: Expectation[];
  public readonly contractIndex!: ContractIndex;
  public readonly contractData!: Map<string, object>;
  public readonly expect!: Expect;
  public readonly web3!: Web3;
  public readonly saddle!: Saddle;
  public readonly printer!: Printer;
  public readonly network!: string;
  public readonly dryRun!: boolean;
  public readonly verbose!: boolean;
  public readonly settings!: Settings;
  public readonly accounts!: Accounts;
  public readonly invokationOpts!: InvokationOpts;
  public readonly trxInvokationOpts!: Map<string, any>;
  public readonly basePath!: string | null;

  public constructor(values?: Partial<WorldProps>) {
    values ? super(values) : super();
  }

  getInvokationOpts(baseOpts: InvokationOpts): InvokationOpts {
    return {
      ...baseOpts,
      ...this.invokationOpts,
      ...this.value ? {value: this.value.toString()} : {}
    };
  }

  isLocalNetwork(): boolean {
    return this.network === 'test' || this.network === 'development' || this.network === 'coverage';
  }

  async updateSettings(fn: (settings: Settings) => Promise<Settings>): Promise<World> {
    // TODO: Should we do an immutable update?
    const newSettings = await fn(this.settings);

    // TODO: Should we await or just let it clobber?
    await newSettings.save();

    return this.set('settings', newSettings);
  }

  defaultFrom(): string | null {
    let settingsFrom = this.settings.findAlias('Me');
    if (settingsFrom) {
      return settingsFrom;
    }

    let accountsDefault = this.accounts.get('default');
    if (accountsDefault) {
      return accountsDefault.address;
    }

    return null;
  }
}
Example #15
Source File: editprofile.state.ts    From spurtcommerce with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
EditprofileRecordState = Record({
  editprofile: [],
  editprofileResponse: false,
  editprofileRequestLoading: false,
  editprofileRequestLoaded: false,
  editprofileRequestFailed: false
})
Example #16
Source File: transactionHelpers.test.ts    From multisig-react with MIT License 4 votes vote down vote up
describe('buildTx', () => {
  it('Returns a valid transaction', async () => {
    // given
    const cancelTx1 = {
      baseGas: 0,
      blockNumber: 0,
      confirmations: [],
      confirmationsRequired: 2,
      data: null,
      dataDecoded: undefined,
      ethGasPrice: '0',
      executionDate: null,
      executor: '',
      fee: '',
      gasPrice: '',
      gasToken: '',
      gasUsed: 0,
      isExecuted: false,
      isSuccessful: true,
      modified: '',
      nonce: 0,
      operation: 0,
      origin: null,
      refundReceiver: '',
      safe: '',
      safeTxGas: 0,
      safeTxHash: '',
      signatures: '',
      submissionDate: null,
      to: '',
      transactionHash: null,
      value: '',
    }
    const transaction = getMockedTxServiceModel({ to: safeAddress2, value: '0' })
    const userAddress = 'address1'
    const cancellationTxs = List([cancelTx1])
    const token = makeToken({
      address: '0x00Df91984582e6e96288307E9c2f20b38C8FeCE9',
      name: 'OmiseGo',
      symbol: 'OMG',
      decimals: 18,
      logoUri:
        'https://github.com/TrustWallet/tokens/blob/master/images/0x6810e776880c02933d47db1b9fc05908e5386b96.png?raw=true',
    })
    const knownTokens = Map<string, Record<TokenProps> & Readonly<TokenProps>>()
    knownTokens.set('0x00Df91984582e6e96288307E9c2f20b38C8FeCE9', token)
    const outgoingTxs = [cancelTx1]
    const safeInstance = makeSafe({ name: 'LOADED SAFE', address: safeAddress })
    const expectedTx = makeTransaction({
      baseGas: 0,
      blockNumber: 0,
      cancelled: false,
      confirmations: List([]),
      creationTx: false,
      customTx: false,
      data: EMPTY_DATA,
      dataDecoded: null,
      decimals: 18,
      decodedParams: null,
      executionDate: '',
      executionTxHash: '',
      executor: '',
      gasPrice: '',
      gasToken: ZERO_ADDRESS,
      isCancellationTx: false,
      isCollectibleTransfer: false,
      isExecuted: false,
      isSuccessful: false,
      isTokenTransfer: false,
      modifySettingsTx: false,
      multiSendTx: false,
      nonce: 0,
      operation: 0,
      origin: '',
      recipient: safeAddress2,
      refundParams: null,
      refundReceiver: ZERO_ADDRESS,
      safeTxGas: 0,
      safeTxHash: '',
      setupData: '',
      status: TransactionStatus.FAILED,
      submissionDate: '',
      symbol: 'ETH',
      upgradeTx: false,
      value: '0',
      fee: '',
    })

    // when
    const txResult = await buildTx({
      cancellationTxs,
      currentUser: userAddress,
      outgoingTxs,
      safe: safeInstance,
      tx: transaction,
    })

    // then
    expect(txResult).toStrictEqual(expectedTx)
  })
})