javascript - How to set a default value -
here how extend immutable.record
import immutable 'immutable'; const data_defaults = { id: string, data: string, ref_id: string, }; export default class data extends immutable.record(data_defaults) {}
if json representation not contain ref_id
, when try print value of field in console of chrome devtool, get:
> data.ref_id string() { [native code] }
i think reason why cannot filter out entities empty ref_id
in list
a = [] // list of data b = a.filter(x => x.ref_id != '') // b same
i suppose can fixed either:
set default value field in
immutable.record
instance when field missing in json datause way detect if field not set in instance
for second approach, have tried, example, data.has('ref_id')
, report true
regardless if field has valid value.
my questions:
1) can set default value in immutable.record
?
2) how filter on field may or may not exist in immutable.record
3) right way test existence of valid value in field in instance of immutable.record
?
you explicitly setting default values of each of fields function string
. string
not data type here, if that's thought. seem want is
const data_defaults = { id: '', data: '', ref_id: '', };
1) can set default value in immutable.record?
exactly how did, need set correct default value.
2) how filter on field may or may not exist in immutable.record
fields on record exist. docs:
records have value keys define. removeing key record resets default value key.
3) right way test existence of valid value in field in instance of
immutable.record
?
you can use default value know not explicitly assigned field otherwise. null
or symbol.
Comments
Post a Comment