How to subclass Immutable.Record?

class Event extends Immutable.Record { constructor(text) { super({text: text, timestamp: Date.now()}); } } 

The call to new Event() returns the constuctor function:

 new Event('started').toString() 

"Record (values) {if (instanceof RecordType values) {return values;}

if (! (this instance of type RecordType)) {return new RecordType (values);}

if (! hasInitialized) {hasInitialized = true; var keys = Object.keys (defaultValues); setProps (RecordTypePrototype, keys); RecordTypePrototype.size = keys.length; RecordTypePrototype._name = name; RecordTypePrototype._keys = keys; RecordTypePrototype._defaultValues ​​= defaultValues;}

this._map = Map (values);} "

While calling the function returns the expected output:

 new Event('started')().toString() 

"Record {" text ":" start "," timestamp ": 1453374580203}"

What am I doing wrong?

+6
source share
1 answer

Immutable.Record " Creates a new class that creates record instances . In other words, this is a function in itself, which you pass to the allowed keys and returns a class you can extend;

 class Event extends Immutable.Record({text:'', timestamp:''}) { constructor(text) { super({text: text, timestamp: Date.now()}); } } > new Event('started').toString() Event { "text": "started", "timestamp": 1453376445769 } 
+12
source

All Articles