This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 404
Convert the FilePatchController hierarchy to React #617
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6b1aaa3
Make FilePatchSelection immutable
smashwilson 8688aa7
Port the HunkView and its tests to React
smashwilson dbd794f
FilePatchView :point_right: React
smashwilson e94187d
Centralize the "resolve this promise the next time X occurs" pattern.
smashwilson 50815ea
Ensure getXyzPromise() and resolveXyzPromise() methods align
smashwilson 13e1596
Support repeated events
smashwilson c47e837
Handle duplicate events correctly.
smashwilson c3bd8b8
Boolean logic is hard, okay
smashwilson 261f00a
FilePatchController tests, so far
smashwilson 40766ed
FilePatchController tests are :white_check_mark:
smashwilson 61fc620
Oh hey I _did_ use that function
smashwilson 4e8efd7
RootController tests are :white_check_mark:
smashwilson bba25e4
:fire: registerHunkView
smashwilson b345897
:burn: usage of `setStatePromise`
smashwilson 0235eb8
RootController integration test to exercise actual PaneItem mounting
smashwilson a2bdf8d
Portal.getView() to construct a view-compatible item
smashwilson 7210d26
Default PaneItem's item to a view
smashwilson 8fb4b0f
Use the default PaneItem getter
smashwilson a1068df
Judicious use of `event.persist`
smashwilson aac603c
Correct FilePatchController focus
smashwilson 6efa684
Always destroy PaneItems on unmount.
smashwilson 2649a99
Work with Enzyme events
smashwilson 89ae013
Mock the FilePatch pane
smashwilson de03a5e
Use either item.destroy() or activePane.destroyItem()
smashwilson b9ee6d5
:fire: setStatePromise
smashwilson 5f5800d
Event subscriptions in componentDidMount
smashwilson 48acdb8
selectAll needs to return a Promise
smashwilson 60f2f1b
My // were showing
smashwilson 028d16b
:fire: duplicate .destroy() check
smashwilson f8704ac
Implement onDidDestroy and destroy again
smashwilson e5c871d
Merge branch 'master' into aw-file-patch-to-react
smashwilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Construct Promises to wait for the next occurrence of specific events that occur throughout the data refresh | ||
* and rendering cycle. Resolve those promises when the corresponding events have been observed. | ||
*/ | ||
export default class EventWatcher { | ||
constructor() { | ||
this.promises = new Map(); | ||
} | ||
|
||
/* | ||
* Retrieve a Promise that will be resolved the next time a desired event is observed. | ||
* | ||
* In general, you should prefer the more specific `getXyzPromise()` methods instead to avoid a proliferation of | ||
* "magic strings." | ||
*/ | ||
getPromise(eventName) { | ||
const existing = this.promises.get(eventName); | ||
if (existing !== undefined) { | ||
return existing.promise; | ||
} | ||
|
||
let resolver, rejecter; | ||
const created = new Promise((resolve, reject) => { | ||
resolver = resolve; | ||
rejecter = reject; | ||
}); | ||
this.promises.set(eventName, { | ||
promise: created, | ||
resolver, | ||
rejecter, | ||
}); | ||
return created; | ||
} | ||
|
||
/* | ||
* Indicate that a named event has been observed, resolving any Promises that were created for this event. Optionally | ||
* provide a payload. | ||
* | ||
* In general, you should prefer the more specific `resolveXyzPromise()` methods. | ||
*/ | ||
resolvePromise(eventName, payload) { | ||
const existing = this.promises.get(eventName); | ||
if (existing !== undefined) { | ||
this.promises.delete(eventName); | ||
existing.resolver(payload); | ||
} | ||
} | ||
|
||
/* | ||
* Indicate that a named event has had some kind of terrible problem. | ||
*/ | ||
rejectPromise(eventName, error) { | ||
const existing = this.promises.get(eventName); | ||
if (existing !== undefined) { | ||
this.promises.delete(eventName); | ||
existing.rejecter(error); | ||
} | ||
} | ||
|
||
/* | ||
* Notified when a hunk or line stage or unstage operation has completed. | ||
*/ | ||
getStageOperationPromise() { | ||
return this.getPromise('stage-operation'); | ||
} | ||
|
||
/* | ||
* Notified when an open FilePatchView's hunks have changed. | ||
*/ | ||
getPatchChangedPromise() { | ||
return this.getPromise('patch-changed'); | ||
} | ||
|
||
/* | ||
* A hunk or line stage or unstage operation has completed. | ||
*/ | ||
resolveStageOperationPromise(payload) { | ||
this.resolvePromise('stage-operation', payload); | ||
} | ||
|
||
/* | ||
* An open FilePatchView's hunks have changed. | ||
*/ | ||
resolvePatchChangedPromise(payload) { | ||
this.resolvePromise('patch-changed', payload); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Very happy to see we can drop this 🙇