-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henrique Barcelos
committed
Aug 28, 2017
1 parent
495854a
commit d1d72c2
Showing
9 changed files
with
321 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export default factory => { | ||
return data => { | ||
const instances = [...data] | ||
.map(factory) | ||
|
||
return Object.create(null, { | ||
toJSON: { | ||
value: function toJSON (context = 'default') { | ||
return instances.map(item => item.toJSON(context)) | ||
} | ||
}, | ||
validate: { | ||
value: function validate (context = 'default') { | ||
const errors = instances.reduce((acc, item) => { | ||
try { | ||
item.validate(context) | ||
return acc | ||
} catch (e) { | ||
return acc.concat(e) | ||
} | ||
}, []) | ||
|
||
if (errors.length > 0) { | ||
throw errors | ||
} | ||
|
||
return this | ||
} | ||
}, | ||
at: { | ||
value: function at (n) { | ||
return instances[n] | ||
} | ||
}, | ||
[Symbol.iterator]: { | ||
value: function * iterator () { | ||
yield * instances[Symbol.iterator]() | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.