Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: store('foo').add({type: 'bar'}) should reject with TypeError
- Loading branch information
Showing
11 changed files
with
54 additions
and
31 deletions.
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
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
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
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
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
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,21 @@ | ||
module.exports = typeCheckWrapper | ||
|
||
function typeCheckWrapper (type, scopedFunction) { | ||
var rejectMessage = '\'type\' field in document does not match scoped store type of \'' + type + '\'' | ||
|
||
return function (objects, secondArgument) { | ||
if (typeErrorExists(objects, type) || typeErrorExists(secondArgument, type)) { | ||
return Promise.reject(new TypeError(rejectMessage)) | ||
} | ||
|
||
return scopedFunction(type, objects, secondArgument) | ||
} | ||
} | ||
|
||
function typeErrorExists (objects, type) { | ||
if (Array.isArray(objects)) { | ||
return objects.some(function (object) { object.type && object.type !== type }) | ||
} | ||
|
||
return typeof objects === 'object' && objects.type && objects.type !== type | ||
} |