Created
June 20, 2017 10:19
-
-
Save kurtmilam/d52724bfc6df7fc903d7426b70266b0b to your computer and use it in GitHub Desktop.
Calmm-js Snippets
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
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