Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Refactor bindings, introducing joinBindings #208

Merged
merged 13 commits into from
Jun 3, 2019
Merged

Conversation

LPGhatguy
Copy link
Contributor

@LPGhatguy LPGhatguy commented May 16, 2019

Inspired by #204. 😄

Reworks bindings from the ground up and adds support for joining bindings together.

Checklist before submitting:

  • Added entry to CHANGELOG.md
  • Added/updated relevant tests
  • Added/updated documentation

Copy link
Contributor

@AmaranthineCodices AmaranthineCodices left a comment

Choose a reason for hiding this comment

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

I think we should throw in the update functions of joined/mapped bindings to catch weird uses of bindings, like using a joined/mapped binding as a reference. I have no idea what happens in that case, but I can't imagine it's very good.

src/Binding.lua Outdated
local disconnect = internalData.changeSignal:subscribe(handler)
internalData.subscriberCount = internalData.subscriberCount + 1
function impl.update(newValue)
-- This operation doesn't make sense; we can leave it as a no-op
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's throw here to catch weird cases (like using a mapped binding as a ref)

src/Binding.lua Outdated
for key, value in pairs(upstreamBindings) do
if Type.of(value) ~= Type.Binding then
local message = (
"Expected arg #1 to contain only bindings, but key %s had a non-binding value"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use %q here, in case the key has spaces or something similarly odd?

src/Binding.lua Outdated
end

return binding, setter
function impl.update(newValue)
-- This operation doesn't make sense; we can leave it as a no-op
Copy link
Contributor

Choose a reason for hiding this comment

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

Should throw here too.

src/Binding.lua Outdated

local BindingInternalApi = {}

local BindingPublicMethods = {}
Copy link

Choose a reason for hiding this comment

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

Should this be changed to bindingPrototype to be congruent with other classes?

function Binding.create(initialValue)
local binding = {
[Type] = Type.Binding,
function impl.subscribe(callback)
Copy link

Choose a reason for hiding this comment

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

Would it make more sense to only subscribe to upstreamBindings once and create/destroy the upstream connections depending on if there are subscribers or not? The prior implementation does this.

Upstream connections could easily add up, considering bindings mapped from this one will invoke subscribe when subscribed to. A good example of this potentially becoming a problem would be when animating transparency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just got back into working on this!

I don't think it's a big deal to pass subscriptions up through to their parents. At the end of the day, someone is going to have to track the connection, and consolidating that at the top is the simplest approach!

src/Binding.lua Outdated
internalData.upstreamDisconnect()
internalData.upstreamDisconnect = nil
local impl = {
disconnectMethods = nil,
Copy link

Choose a reason for hiding this comment

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

This variable is unused.

Copy link
Contributor

@ZoteTheMighty ZoteTheMighty left a comment

Choose a reason for hiding this comment

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

This looks solid as far as I can tell. I think it's a bit more approachable than the previous implementation, especially with the addition of joinBindings.

@LPGhatguy LPGhatguy marked this pull request as ready for review May 28, 2019 20:47
@LPGhatguy
Copy link
Contributor Author

PR feedback was addressed and I added a changelog entry and (bad) documentation.

I'm not sure what a small sample for how to use joinBindings would be; the current one is quite large.

@coveralls
Copy link

coveralls commented May 30, 2019

Coverage Status

Coverage increased (+0.1%) to 93.204% when pulling ac32d5d on refactor-bindings into 8e89c42 on master.

@ZoteTheMighty ZoteTheMighty self-requested a review May 30, 2019 22:47
Copy link
Contributor

@ZoteTheMighty ZoteTheMighty left a comment

Choose a reason for hiding this comment

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

Docs look fine for now, test additions make sense. LGTM.

@Reselim
Copy link

Reselim commented Jun 2, 2019

LGTM! Works well in my (rather large) UI codebase making use of joinBindings.

@LPGhatguy
Copy link
Contributor Author

Will merge this first thing Monday to cut 1.1!

@LPGhatguy LPGhatguy merged commit 7a6a2dd into master Jun 3, 2019
@LPGhatguy LPGhatguy deleted the refactor-bindings branch June 3, 2019 18:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants