How to use the @ngxs/store/operators.patch function in @ngxs/store

To help you get started, we’ve selected a few @ngxs/store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xlayers / xlayers / src / app / core / state / ui.state.ts View on Github external
layerPosition({ setState }: StateContext, action: LayerPosition) {
    // reset the top/left position of the current page
    // and the root layer
    setState(
      patch({
        currentPage: patch({
          frame: patch({
            x: action.left,
            y: action.top
          })
        })
      })
    );
  }
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
}

        ctx.setState(
            patch({
                availableUsers: updateItem(a => a.userName === foundUser.userName, foundUser)
            })
        )
        if (ObjectUtils.isNotNull(foundRoom)) {
            return ctx.dispatch(new ChatActions.ActiveDoubleChatRoom({
                chatSession: foundRoom.currentSession
            }))
        }
        else {
            // No found room, mean need to fetch from server
            ctx.setState(
                patch({
                    invitingUser: event.inviee
                })
            )
            // Notify Chat Service to init double chat room
            return ctx.dispatch(new ChatActions.FetchDoubleChatRoom())
        }
    }
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
public clickedOnChatBoxIcon(ctx: StateContext, { event }: ChatActions.ClickedOnChatBox) {
        const state = ctx.getState()
        const foundRoom = state.chatRooms.find(a => a.chatRoomId === event.chatRoomId)
        if (ObjectUtils.isNotNull(foundRoom)) {
            // Clear all messages
            let notifiedChatRooms: string[] = ObjectUtils.clone(state.notifiedChatRooms)
            if (ObjectUtils.isNotNull(notifiedChatRooms)) {
                notifiedChatRooms = notifiedChatRooms.filter(a => a !== foundRoom.chatRoomId)

                ctx.setState(
                    patch({
                        notifiedChatRooms: notifiedChatRooms
                    })
                )
            }
            return ctx.dispatch(new ChatActions.ActiveDoubleChatRoom({
                chatSession: foundRoom.currentSession
            }))
        }
    }
github xlayers / xlayers / src / app / core / state / ui.state.ts View on Github external
zoomOut({ getState, setState }: StateContext, action: ZoomOut) {
    const zoomLevel = parseFloat(
      (getState().zoomLevel - action.value).toFixed(2)
    );

    setState(
      patch({
        zoomLevel: iif(zoomLevel >= 0.1, zoomLevel)
      })
    );
  }
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
public forceDroppedCall(ctx: StateContext, { error }: ChatActions.ForceDroppedCall) {
        return ctx.setState(
            patch({
                handshakedVideoCall: null,
                iceServer: null,
                incomingVideoCall: null,
                inviterVideoCall: null,
                callErrorCode: error
            })
        )
    }
}
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
public toggleOpenChatRoom(ctx: StateContext, { toggle }: ChatActions.ToggleOpenChatRoom) {
        const state = ctx.getState()
        return ctx.setState(
            patch({
                isOpenChatBox: toggle
            })
        )
    }
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
public loadedAllUsers(ctx: StateContext, { event }: ChatActions.LoadedAllAvailableUsers) {
        event.availableUsers.forEach(u => {
            u.incomingMessages = 0
        })
        return ctx.setState(
            patch({
                availableUsers: event.availableUsers
            })
        )
    }
github phucan1108 / letportal / src / web-portal / src / app / core / stores / chats / chats.state.ts View on Github external
public incomingVideoCall(ctx: StateContext, { event }: ChatActions.NotifyIncomingVideoCall) {
        const foundUser = ctx.getState().availableUsers.find(a => a.userName === event.caller.username)
        return ctx.setState(
            patch({
                incomingVideoCall: event.caller,
                inviterVideoCall: foundUser
            })
        )
    }
github abritopach / angular-ionic-ngxs-movies / src / app / store / state / movies.state.ts View on Github external
deleteFavoriteMovie({ setState }: StateContext, { payload }) {
        setState(
            patch({
                favorites: removeItem(movie => movie.id === payload.id)
            })
        );
    }
github xlayers / xlayers / src / app / core / state / ui.state.ts View on Github external
zoomIn({ getState, setState }: StateContext, action: ZoomIn) {
    const zoomLevel = parseFloat(
      (getState().zoomLevel + action.value).toFixed(2)
    );

    setState(
      patch({
        zoomLevel: iif(zoomLevel <= 3, zoomLevel)
      })
    );
  }