How to construct subclasses of Immutable.Record?

后端 未结 1 544
心在旅途
心在旅途 2021-01-18 01:17
class Event extends Immutable.Record {
  constructor(text) {
    super({text: text, timestamp: Date.now()});
  }
}

Calling new Event()

相关标签:
1条回答
  • 2021-01-18 01:48

    Immutable.Record "Creates a new Class which produces Record instances.", in other words it's a function in itself which you pass 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 }
    
    0 讨论(0)
提交回复
热议问题