Skip to content

Instantly share code, notes, and snippets.

@kurtmilam
Created June 20, 2017 10:19
Show Gist options
  • Save kurtmilam/d52724bfc6df7fc903d7426b70266b0b to your computer and use it in GitHub Desktop.
Save kurtmilam/d52724bfc6df7fc903d7426b70266b0b to your computer and use it in GitHub Desktop.
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