Skip to content

[Feat Request]: Coordinator instance based atom state management #19

@ra1028

Description

@ra1028

Checklist

  • Reviewed the README and documentation.
  • Checked existing issues & PRs to ensure not duplicated.

Description

Support managing a class instance with Coordinator like UIViewRepresentable instead of context.addTermination and context.keepUntilTermination.

Example Use Case

struct ExampleManagerAtom: ValueAtom, Hashable {
    final class Coordinator: ExampleDelegate {
        func delegateMethod() { ... }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator()
    }

    func value(context: Context) -> ExampleManager {
        let manager = ExampleManager()
        manager.delegate = context.coordinator
        return manager
    }
}

Alternative Solution

N/A

Proposed Solution

  • Add an associated type Coordinator which is Void by default.
  • Add makeCoordinator() -> Coordinator method which is empty by default.
  • Maintain coordinator instance in core system and terminate it when the atom state is invalidated.

Motivation & Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions