Skip to content

Support SkipRepeats  #5

Open
Open
@ranhsd

Description

@ranhsd

Hi,

I wanted to know if this library support or maybe can support SkipRepeats.

What is SkipRepeats + Example:

SkipRepeats allows ReSwift framework to skip and not trigger the newState delegate method in case the sub-state was not changed. It's really simple but very helpful feature that can boost apps performance.

Let's assume that I have the following AppState in my app:

struct AppState : StateType, HasNavigationState {
    var itemState: ItemState,
    var currentUserState: CurrentUserState
}

In order to use skip repeats you need to divide your AppState to sub-states and subscribe to the sub state (or part of it) in the view controller. Each sub-state must conform to Equatable, this way the framework can detect if the sub-state has been changed or not (after dispatching an action) and only if it was changed then the newState method will be called.

So current user state looks like the following:

struct CurrentUserState : StateType {
    var name: String?
    var currentUserId: String?
   .... 
}

extension CurrentUserState : Equatable {
    static func ==(lhs: CurrentUserState, rhs: CurrentUserState) -> Bool {
        return lhs.currentUserId == rhs.currentUserId &&
            lhs.name == rhs.name
    }
}

Now, because ReSwift implemented selectors you can subscribe only to part of your state inside your view controller:

        store.subscribe(self) {subscription in
            subscription.select {state in
                state.currentUserState }.skipRepeats()
        }

As you can see from the code above, If I put skipRepeats() the view controller newState (the subscriber) will be called only if the currentUserState changed.

SkipRepeats is a small but very powerful feature that can lead to big improvements in the performance of an app and especially for a big apps.

I wanted to know if it is possible to support skipRepeats in this library as well or maybe it is already supported and I am missing something?

Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions