Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/models/ref-holder.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ export default class RefHolder {
return Promise.resolve(this.get());
}

map(block) {
if (!this.isEmpty()) {
return block(this.get());
}
return null;
map(present, absent = () => this) {
return RefHolder.on(this.isEmpty() ? absent() : present(this.get()));
}

setter = value => {
Expand Down
8 changes: 4 additions & 4 deletions lib/views/commit-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export default class CommitView extends React.Component {
}

excludeCoAuthor() {
const author = this.refCoAuthorSelect.map(c => c.getFocusedOption());
const author = this.refCoAuthorSelect.map(c => c.getFocusedOption()).getOr(null);
if (!author || author.isNew()) {
return;
}
Expand Down Expand Up @@ -548,15 +548,15 @@ export default class CommitView extends React.Component {
return CommitView.focus.EDITOR;
}

if (this.refAbortMergeButton.map(e => e.contains(event.target))) {
if (this.refAbortMergeButton.map(e => e.contains(event.target)).getOr(false)) {
return CommitView.focus.ABORT_MERGE_BUTTON;
}

if (this.refCommitButton.map(e => e.contains(event.target))) {
if (this.refCommitButton.map(e => e.contains(event.target)).getOr(false)) {
return CommitView.focus.COMMIT_BUTTON;
}

if (this.refCoAuthorSelect.map(c => c.wrapper.contains(event.target))) {
if (this.refCoAuthorSelect.map(c => c.wrapper.contains(event.target)).getOr(false)) {
return CommitView.focus.COAUTHOR_INPUT;
}

Expand Down
45 changes: 45 additions & 0 deletions test/models/ref-holder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,51 @@ describe('RefHolder', function() {
assert.strictEqual(h.get(), 1234);
});

describe('map', function() {
it('returns an empty RefHolder as-is', function() {
const h = new RefHolder();
assert.strictEqual(h.map(() => 14), h);
});

it('returns a new RefHolder wrapping the value returned from its present block', function() {
const h = new RefHolder();
h.setter(12);
assert.strictEqual(h.map(x => x + 1).get(), 13);
});

it('returns a RefHolder returned from its present block', function() {
const h0 = new RefHolder();
h0.setter(14);

const o = h0.map(() => {
const h1 = new RefHolder();
h1.setter(12);
return h1;
});

assert.notStrictEqual(0, h0);
assert.strictEqual(o.get(), 12);
});

it('returns a new RefHolder wrapping the value returned from its absent block', function() {
const h = new RefHolder();

const o = h.map(x => 1, () => 2);
assert.strictEqual(o.get(), 2);
});

it('returns a RefHolder returned from its absent block', function() {
const h0 = new RefHolder();

const o = h0.map(x => 1, () => {
const h1 = new RefHolder();
h1.setter(1);
return h1;
});
assert.strictEqual(o.get(), 1);
});
});

it('notifies subscribers when it becomes available', function() {
const h = new RefHolder();
const callback = sinon.spy();
Expand Down