-
Notifications
You must be signed in to change notification settings - Fork 3
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: Move Context object to new class #929
Conversation
6565d01
to
5dedec3
Compare
return data; | ||
} | ||
|
||
buildContext (blockHeight: number, logEntries: LogEntry[]): ContextObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about integrating the functions into this class itself, or having a persistent object to update, but I wasn't sure how that would work when frozen into the VM or with any references to class variables. I decided to continue building an object when requested.
} | ||
} | ||
|
||
// TODO: Migrate all below code to separate class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the below code will be moved to its own class and have its own unit tests. I've simply placed them here for now to reduce PR size.
@@ -0,0 +1,292 @@ | |||
import fetch from 'node-fetch'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to start nesting relating components in the filesystem to provide some additional context in to the relationships in our codebase, e.g. butting context-builder
under indexer
as it's directly related to that? src/
is starting to grow so would be good to start encapsulating/grouping related logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point. I'll do that now then for this class and move some more in the follow up DmlHandler one.
All logic associated with the creation of the context object resides inside the Indexer class, which bloats the file and complicates unit testing. In addition, it prevents access to the context object itself so that these calls can be made through the Indexer class itself.
This PR refactors this logic into its own class, allowing access to context methods through Indexer. The object is still recreated each time it is accessed as the object bakes in some state information (block height and log entry array) which need to be updated on subsequent accesses.
I've also reorganized the folders so that we have fewer folders under src as it is getting cluttered.