Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Last active November 12, 2020 07:12
Show Gist options
  • Select an option

  • Save guillaumewuip/63f6f348dd8d83b369c1d6f992e37ab6 to your computer and use it in GitHub Desktop.

Select an option

Save guillaumewuip/63f6f348dd8d83b369c1d6f992e37ab6 to your computer and use it in GitHub Desktop.

Revisions

  1. guillaumewuip revised this gist Nov 12, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.ts
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ export const addUser = (user: User.User) => (

    return {
    ...state,
    users: NonEmptyArray.snoc(state.users, user)
    users: [...state.users, user]
    };
    };

  2. guillaumewuip revised this gist Nov 12, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ export const addUser = (user: User.User) => (
    };
    };

    export const isLoading = (state: State): state is Loading => ...;
    export const isError = (state: State): state is Failure => ...;
    export const isLoading = (state: State): state is Loading => // ...
    export const isError = (state: State): state is Failure => // ...

    export const canCreateUser = (state: State): boolean => ...;
    export const canCreateUser = (state: State): boolean => //...
  3. guillaumewuip renamed this gist Nov 12, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. guillaumewuip created this gist Nov 12, 2020.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    export const decode = (apiPayload: unknown): Loaded | Failure => {
    // parse payload
    // remove admins
    // if something goes wrong, return Failure
    };

    export const users = (state: Loaded) => state.users;

    export const addUser = (user: User.User) => (
    state: Loaded
    ): Loaded | Failure => {
    if (state.users.length >= 10) {
    return new Error("oops");
    }

    return {
    ...state,
    users: NonEmptyArray.snoc(state.users, user)
    };
    };

    export const isLoading = (state: State): state is Loading => ...;
    export const isError = (state: State): state is Failure => ...;

    export const canCreateUser = (state: State): boolean => ...;