Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calmm-js Snippets
const obsv = someObservable // stream, atom, etc.
const record = U.view( 'record', obsv )
const nameDefault = 'nobody'
const nameL = 'name'
const defaultsTemplate = { /* some defaults*/ }
obsv.onValue(
R.pipe( L.transform( [ nameL
, L.when( R.isNil )
, L.setOp( nameDefault )
]
)
// ^^^ Applies a default value to a single property at transform focus ('name')
// Apply a template of default values via merge
// R.deepMerge is not yet available in the boilerplate
, L.modify( 'iNeedDefaults'
, R.merge( defaultsTemplate )
)
// Set the atom
, R.tap( x => record.set( x ) ) // keep the lambda
// The lamda is necessary, for some reason
// I'm using R.tap here in case we need to continue working with the data
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.