Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/create-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const canonize = r.pipe(
)

const explodeOnUnknownProp = (obj, prop) => {
if (prop === '@@functional/placeholder') {
return
}

if (prop in obj) {
return obj[prop]
}
Expand Down Expand Up @@ -86,5 +90,13 @@ export const createType = propDefs => {
over: r.map(r.over)(lenses)
})

return r.merge(fnsPerProp, { pickAll: r.pick(r.values(nameMap)) })
const pickAll = r.pick(r.values(nameMap))

return r.merge(fnsPerProp, {
pickAll,
allProps: r.pipe(
pickAll,
r.values
)
})
}
14 changes: 13 additions & 1 deletion src/create-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ describe('KISS type', () => {
})
it('fails on attempted access to unknown props', () => {
const failsNicely = __.throws(
__.typedError(TypeError, __.containsString('unknown'))
__.typedError(TypeError, __.containsString('Unknown'))
)
__.assertThat(() => type.get.unknown, failsNicely)
__.assertThat(() => type.set.unknown, failsNicely)
})
it('all props can be retrieved with ramda', () => {
const doesNotThrow = __.not(__.throws())

const getAllProps = r.pipe(
r.prop('props'),
r.values
)
__.assertThat(() => getAllProps(type), doesNotThrow)
})
it('all props can be retrieved via allProps', () => {
__.assertThat(type.allProps({ prop: 42 }), __.is([42]))
})
})

describe('with getter enhancer', () => {
Expand Down