question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seamless-Immutable & Flow

See original GitHub issue

Anybody an idea how to write a module declaration for this or how to use seamless with flow type? Any recommendations? Where to start, here we tried and failed badly a couple of times …

declare module 'seamless-immutable' {
  declare class SeamlessImmutableCollection {
    (collection: any, prototype?: Object, depth?: number): SeamlessImmutableCollection,

    /* array functions */
    flatMap(fn: Function): Array<any>,
    asObject(fn: Function): Object,
    asMutable(): Array<any>,

    /* object functions */
    merge(collection: Array<any> | Object, deep?: Object): Object,
    set(key: string, value: any): Object,
    setIn(keyPath: Array<string>, value: any): Object,
    update(key: string, fn: Function): Object,
    updateIn(keyPath: Array<string>, fn: Function): Object,
    without(fn: Function): Object,
    without(keys: Array<string>): Object,
    without(...keys: Array<string>): Object,
    asMutable(): Array<any> | Object
  }

  declare var exports: SeamlessImmutableCollection;
}

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:25 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
chrisbullcommented, Nov 8, 2017

@azundo Found this…

https://gist.github.com/mizchi/3054bca701dff4b5e28efd9133c66818

seems to be working great for me thus far.

import Immutable, { type Immutable as ImmutableType } from 'seamless-immutable'

type LoginState = {
  authToken: string,
  error: any,
  fetching: boolean,
  loading: boolean,
}

type _LoginState = ImmutableType<LoginState>

const INITIAL_STATE: _LoginState = Immutable({
  authToken: '',
  error: null,
  fetching: false,
  loading: false,
})

export const request = (state: _LoginState): _LoginState =>
  state.merge({ fetching: true })
1reaction
KROT47commented, Jun 28, 2017

With ES modules support:

/* @flow */

declare module 'seamless-immutable' {
  declare type fromType = Object | Array<*>;

  declare export type Immutable<T: fromType> = T & {
    // Array methods
    flatMap(fn: Function): Array<any>;
    asObject(fn: Function): Object;
    asMutable(): Array<any>;
    // Object methods
    merge(collection: Array<any> | Object, deep?: Object): Object;
    set(key: string, value: any): Object;
    setIn(keyPath: Array<string>, value: any): Object;
    update(key: string, fn: Function): Object;
    updateIn(keyPath: Array<string>, fn: Function): Object;
    without(fn: Function): Object;
    without(keys: Array<string>): Object;
    without(...keys: Array<string>): Object;
    asMutable(): Array<any> | Object;
  };

  declare export function from<T: fromType> (spec: T): Immutable<T>;

  declare export function isImmutable(x: *): boolean;

  declare export default typeof from;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Immutable.js vs Seamless-immutable | by Peter Kowalczyk
2. API. Set — sets new data in the same object. Get — no getters, while we can access data as follows ...
Read more >
Immutable Data Structures That Are Compatible with Normal ...
- Utilities that abstract over immutably updating plain JS objects and arrays. seamless-immutable falls into the second category. Looks like it ...
Read more >
Immutability in JavaScript Using Redux - Toptal
This process enforces unidirectional data flow, which is easier to understand ... immutable array via seamless-immutable /** * a reducer takes a state...
Read more >
seamless-immutable is not updating state consistently
I'm working with seamless-immutable and redux, and I'm getting a strange error when ... Why do we need middleware for async flow in...
Read more >
Approaches to Immutability – an article by 500Tech
Both ImmutableJS and seamless-immutable are libraries that wrap ... import { flow, set, update } from 'lodash/fp' flow([update('parent.key', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found