Add runtime.interactions(for:) API for fetching interactions associated with a given target.
ClosedPublic

Authored by featherless on Apr 14 2017, 5:49 PM.

Diff Detail

Repository
rREACTIVEMOTIONSWIFT reactive-motion-swift
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
featherless created this revision.Apr 14 2017, 5:49 PM
Restricted Application added a reviewer: O2: Material Motion. · View Herald TranscriptApr 14 2017, 5:49 PM
Restricted Application added a project: Material Motion. · View Herald Transcript
Restricted Application added a reviewer: O4: Material Apple platform reviewers. · View Herald Transcript
Restricted Application added a reviewer: Material Motion. · View Herald Transcript
  • Simplify the code.
appsforartists accepted this revision.Apr 15 2017, 2:25 AM
This revision is now accepted and ready to land.Apr 15 2017, 2:25 AM
markwei accepted this revision.Apr 15 2017, 3:08 AM
markwei added a subscriber: markwei.
markwei added inline comments.
src/MotionRuntime.swift
84

Just making sure, you couldn't have a method signature like:

public func interactions<I: Interaction>(for target: I.Target, flatMap: (Any) -> I?) -> [I] {
}

IOW: Given a target of type O, only allow:

  • a flatmap of type (Any) -> I? such that I.Target == O
  • a return value type of [I] such that I.Target == O.

You can create such a constraint in java with:

public <I extends Interaction<O,?>, O> I[] interactions(O target, Function<Object, I> flatmap) {
}
featherless added inline comments.Apr 17 2017, 1:20 PM
src/MotionRuntime.swift
84

Good insight. I've touched up the code to remove the flatMap.

  • Simplify the code.
  • Clean up and simplify.
markwei added inline comments.Apr 17 2017, 1:30 PM
tests/unit/MotionRuntimeTests.swift
37

cool - i assume the type inference would fail if you did not declare this var as results: [Draggable] = and used the shorthand results = instead?

featherless added inline comments.Apr 17 2017, 1:32 PM
tests/unit/MotionRuntimeTests.swift
37

Yeah. I think this may be a bit too magic; probably better for someone to learn how to use flatMap than to have to deal with a confusing compiler error because of no explicit type provision. I'm going to revert this back to the explicit flatMap version.

markwei added inline comments.Apr 17 2017, 1:34 PM
tests/unit/MotionRuntimeTests.swift
37

Agreed. In java, a var is always declared with its explicit type, so this is not a problem.

Another suggestion brought up by eric is runtime.interactions(viewTarget, Draggable.class). Such a thing is possible in java, and is used by some framework APIs.

  • Simplify the code.
  • Clean up and simplify.
  • Revert to more explicit API.
Restricted Application completed building Restricted Buildable.Apr 17 2017, 1:35 PM
featherless added inline comments.Apr 17 2017, 1:42 PM
tests/unit/MotionRuntimeTests.swift
37

I don't see an immediate clear path to the API proposed by eric. Will explore in the future as I believe it should be buildable atop this flatMap API.

This revision was automatically updated to reflect the committed changes.