Skip to content

Conversation

@quickthyme
Copy link
Owner

@quickthyme quickthyme commented Jul 12, 2019

Basically a cheap way to provide some basic broadcast-like capabilities.

NOTE: Depends on PR #7

Repeaters

Repeaters offer a way to fork multiple streams off of the main path.

When an Anchor has repeaters applied, then it will echo any value and error changes
to each of them.

By default, it forwards all changes to all repeaters. In order to make it conditional, we can
set an EchoFilter, which gets called prior to forwarding to each repeater. Return false
from the EchoFilter to block that repeater from receiving the change.

EchoFilter
  • (Input?, QLAnchor) -> (Bool)

Default filter returns true. You can evaluate the input value and decide whether or not the
particular anchor (repeater) should receive the new value.

To identify the anchor, you will need to do so using the object reference.

example:

let progressRepeater = viewController.progressAnchor
let finalRepeater = viewController.downloadCompleteAnchor

let baseAnchor = QLAnchor<DownloadStatus>(
    echoFilter: ({ obj, repeater in
        return (obj.isProgress && repeater === progressRepeater)
            || (obj.isFinal && repeater === finalRepeater)
    }),
    repeaters: progressRepeater, finalRepeater
)

Signed-off-by: James Hall <james.hall@vmlyr.com>
Signed-off-by: James Hall <james.hall@vmlyr.com>
@quickthyme quickthyme force-pushed the feature/anchor-repeater branch from 19c3369 to 6721d2e Compare July 12, 2019 18:18
Signed-off-by: James Hall <james.hall@vmlyr.com>
let errGettable = newValue as? ErrorGettable,
let err = errGettable.getError() {

if let err = getReroutableError(newValue) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏅

@diedrix diedrix self-requested a review July 12, 2019 19:05
@quickthyme quickthyme merged commit 9c6991d into master Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants