Skip to content

Commit

Permalink
Add identifiable routing state
Browse files Browse the repository at this point in the history
  • Loading branch information
Daeda88 committed Feb 9, 2022
1 parent 50fbbfd commit 073f922
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions stencils/RoutingState.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,49 @@ class ObjectRoutingState<T: Equatable>: RoutingState {
super.close(animated: animated, force: force)
}
}

class IdentifiableRoutingState<ID : Equatable> : RoutingState {
private(set) var id: ID?

func show(_ id: ID, animated: Bool = false) {
let force: Bool
if self.id != id {
self.id = id
force = true
} else {
force = false
}
super.show(animated: animated, force: force)
}

override func close(animated: Bool = false, force: Bool = false) {
id = nil
super.close(animated: animated, force: force)
}
}

class IdentifiableObjectRoutingState<T, ID>: IdentifiableRoutingState<ID> where T : Equatable, T : Identifiable, T.ID == ID {

private(set) var object: T?
override var id: ID? {
get {
object?.id
}
}

func show(_ object: T, animated: Bool = false) {
let force: Bool
if self.object != object {
self.object = object
force = true
} else {
force = false
}
super.show(animated: animated, force: force)
}

override func close(animated: Bool = false, force: Bool = false) {
object = nil
super.close(animated: animated, force: force)
}
}

0 comments on commit 073f922

Please sign in to comment.