I'm currently delving into the world of immutable.js record and trying to wrap my head around it.
However, this particular piece of code is really throwing me for a loop.
Here's my Question:
- I understand [import, export,const], but what exactly does [type] signify?
- Can you explain the meanings behind
defaultValues:
,makePoint3D:
,getName(): string
,setName(name: string): this
? I've never encountered:
used in this context before.
This question is crucial for my comprehension of the topic.
Please share your insights and advice!
import type { RecordFactory, RecordOf } from 'immutable';
// Use RecordFactory<TProps> for defining new Record factory functions.
type Point3DProps = { x: number, y: number, z: number };
const defaultValues: Point3DProps = { x: 0, y: 0, z: 0 };
const makePoint3D: RecordFactory<Point3DProps> = Record(defaultValues);
export makePoint3D;
// Use RecordOf<T> for defining new instances of that Record.
export type Point3D = RecordOf<Point3DProps>;
const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
type PersonProps = {name: string, age: number};
const defaultValues: PersonProps = {name: 'Aristotle', age: 2400};
const PersonRecord = Record(defaultValues);
class Person extends PersonRecord<PersonProps> {
getName(): string {
return this.get('name')
}
setName(name: string): this {
return this.set('name', name);
}
}
Source: