Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor towards three-layer architecture #122

Merged
merged 5 commits into from
Mar 25, 2016

Conversation

alandotcom
Copy link
Contributor

Create app container
Pass services down into lower layers (lower layers don't require singletons from src/services)

TODO:

  • Move common utils (e.g., services/log) to common

@alandotcom
Copy link
Contributor Author

cc @gip -- config is now passed down from top layer

app: app,
listen: listen,
app: connector.koaApp,
listen: connector.listen,
addLedger: ledgers.addLedger.bind(ledgers),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this doable with with _.partial, as in app.js (for consistency)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just grepped for addLedger and it's not used

Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't used internally, which is why it is exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where is it used? (Curious)

Copy link
Contributor

Choose a reason for hiding this comment

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

@clark800
Copy link
Contributor

I’m pondering the DI structure. One thing I've noticed is that refactoring things like this can be quicker if you use keyword arguments because for example if you want to delete one of them, you can just delete it where it is used and where it is passed in and you don’t have to change all the intermediate functions that were just passing it through. So we might want to consider using a "context" object to hold all the dependency injection objects. It also gives you a logical separation between the DI parameters and non-DI parameters.

@clark800
Copy link
Contributor

I'm not sure if we're getting much advantage to passing the backend around as a parameter because the config already specifies the backend, so wherever you need the backend you could just call a function that loads the proper backend based on the config. Or am I missing something? Also, I haven't figured out what the ledgers parameter is used for yet. I'm wondering if there is a way we can avoid passing that around too.

@alandotcom
Copy link
Contributor Author

@clark800 I think maybe I can followup with a later commit to avoid needing to pass some things down. The config specifies a backend type, which is then require'ed in services/backend.

@emschwartz
Copy link
Member

Could you provide more context for the purpose of this refactoring? Is there a specific issue that motivated it or is it just to comply with the 3-layer architecture design?

@clark800
Copy link
Contributor

Also, we could even eliminate a lot of the config parameters by passing it at the module level like this

const makeExports = (config) => {
  getX: (param) => {
    ... // have access to config here even though it isn't a parameter to the getX function
  }
}

module.exports = makeExports

@alandotcom
Copy link
Contributor Author

@clark800 I like that approach.
@emschwartz discussion is here interledger-deprecated/five-bells-ledger#112

@MatthewPhinney
Copy link
Contributor

Is there a specific issue that motivated it or is it just to comply with the 3-layer architecture design?

@emschwartz my understanding was that this was partly motivated by the desire to unit test different quoter backends. With this refactor, we can pass the config as a param into the instantiation of the app, allowing us to switch quoter backends. See here. Is this correct @LumberJ?

@emschwartz
Copy link
Member

Sounds like a use case for https://github.com/justmoon/reduct

On Wed, Mar 23, 2016 at 3:15 PM, Matthew Phinney [email protected]
wrote:

Is there a specific issue that motivated it or is it just to comply with
the 3-layer architecture design?

@emschwartz https://github.com/emschwartz my understanding was that
this was partly motivated by the desire to unit test different quoter
backends. With this refactor, we can pass the config as a param into the
instantiation of the app, allowing us to switch quoter backends. See here
https://ripplelabs.atlassian.net/browse/RILP-284. Is this correct
@LumberJ https://github.com/lumberj?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#122 (comment)

Evan Schwartz | Software Architect | Ripple
[image: ripple.com] http://ripple.com

@alandotcom
Copy link
Contributor Author

@MatthewPhinney Yes, that's one of a few things

Alan Cohen added 2 commits March 24, 2016 17:38
Create app container
Pass services down into lower layers (lower layers don't require singletons from src/services)

TODO:
- Move common utils (e.g., services/log) to `common`
- BalanceCache not used by default (i.e., caching is behind feature
  flag) and not a singleton.
@clark800
Copy link
Contributor

Maybe a cleaner way of doing it:

module.exports = function (config) {

  function getX (param) {

  }

  function getY (param) {

  }

  return {getX, getY}
}

@alandotcom
Copy link
Contributor Author

@clark800
Copy link
Contributor

LGTM

@alandotcom alandotcom merged commit 68d7345 into interledgerjs:master Mar 25, 2016
@alandotcom alandotcom deleted the three-layer/app branch March 25, 2016 23:08
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.

5 participants