-
Notifications
You must be signed in to change notification settings - Fork 710
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
Prep for GameLog stuff: Introduce ContextEnhancer #261
Prep for GameLog stuff: Introduce ContextEnhancer #261
Conversation
src/core/random.js
Outdated
update(ctx) { | ||
return { ...ctx, _random: this.state }; | ||
update(state) { | ||
var newCtx = { ...state.ctx, _random: this.state }; |
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.
This can be written more concisely as:
const ctx = { ...state.ctx, _random: this.state };
return { ...state, ctx };
src/core/reducer.js
Outdated
initial.ctx = Random.detach(initial.ctx); | ||
initial.ctx = Events.detach(initial.ctx); | ||
initial.ctx = apiCtx.random.update(initial).ctx; | ||
initial.ctx = apiCtx.detachFromContext(initial.ctx); |
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.
state = apiCtx.update(state);
initial.ctx = state.ctx;
initial.ctx = apiCtx.detachFromContext(initial.ctx);
should work here.
A more interesting observation is given that update
is always followed by a detachFromContext
, shall we combine them into one call detach
that accepts state
and returns state
?
This PR is written as prep work for #227, where we want to attach a
log
object to the context, allowing a game to write custom logging information. It introduces a class calledContextEnhancer
that ties all APIs together that can be attached and detached from a context - currently, these arerandom
andevents
. This results inAlbeit I failed to also fixup the code creating the initial state, I've not exactly pinpointed why using
ctxApi.update()
does not work. The flow of the various state and context objects gets unwieldy, too. And perhaps there are other places that could use that class also.Let me know what you think.
Checklist
master
).