-
Notifications
You must be signed in to change notification settings - Fork 117
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
Resolve addPromised
with new doc id
#305
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c0fe35
Pass id of newly created doc in callback form add and resolve with id…
craigbeck f1d9dc7
Typo fixes
craigbeck 8ec99d1
Change to use let
craigbeck 4e19a9c
Change ValueCallback value to non-optional; rename wrapped callback i…
craigbeck f8d9691
Merge branch 'master' of github.com:derbyjs/racer into addPromised-id
craigbeck 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 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 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,23 @@ | ||
const {expect} = require('chai'); | ||
const {RootModel} = require('../../lib/Model'); | ||
|
||
describe('mutators', () => { | ||
describe('add', () => { | ||
const guidRegExp = new RegExp(/[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}/); | ||
it('returns created id in callback', () => { | ||
const model = new RootModel(); | ||
model.add('_test_doc', {name: 'foo'}, (error, id) => { | ||
expect(error).to.not.exist; | ||
expect(id).not.to.be.undefined; | ||
expect(id).to.match(guidRegExp, 'Expected a GUID-like Id'); | ||
}); | ||
}); | ||
|
||
it('resolves promised add with id', async () => { | ||
const model = new RootModel(); | ||
const id = await model.addPromised('_test_doc', {name: 'bar'}); | ||
expect(id).not.to.be.undefined; | ||
expect(id).to.match(guidRegExp, 'Expected a GUID-like Id'); | ||
}); | ||
}); | ||
}); |
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.
return type 'undefined' is not assignable to type 'string'. consider adding to your interface : string | undefined
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.
@ericyhwang what do you think of throwing an error here? Optional callback isn't great for the error handling case as this is really argument validation (so before any "work" that would result in callback call) but I'm unclear as to impacts or likelihood of this case. No id to return, and don't like the optional string return for downstream implications.
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.
FWIW Typescipt is okay with this (incompletely typed), and as this is what already exists in current code, It's what it will stay with for now.
Does highlight another point though... our type sigs allow
value: any
and not constrained toobject
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.
Throwing an error seems reasonable to me. Should be rare to encounter, since most calls to
add
should be with an argument that's statically known to be an object.Only concern would be that the caller may not be set up to handle a thrown error.
Either way, let's leave it alone for now. Even if we did want to change it to a thrown error, we should do it in a separate change, and also apply the change to the other mutator methods too.