Skip to content

Return subscription dispose function directly from subscription function #46

@atheck

Description

@atheck

Instead of writing something like:

let backHandlerSubscription: NativeEventSubscription | null = null;

const sub = (dispatch: Dispatch<Message>): void => {
  backHandlerSubscription = BackHandler.addEventListener("hardwareBackPress", handler);
};

return [cmd.ofSub(sub), () => backHandlerSubscription?.remove()];

Write:

const sub = (dispatch: Dispatch<Message>): () => void => {
  const backHandlerSubscription = BackHandler.addEventListener("hardwareBackPress", handler);

  return () => backHandlerSubscription.remove()
};

return [cmd.ofSub(sub)];

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions