上QQ阅读APP看书,第一时间看更新
Adding active record support to our state
Before we look at our actual database code, we need to introduce one last piece of the puzzle—the object that we are going to store. While we have been working with state, we have been using IPersonState to represent the state of a person and, as far as the PersonalDetails component goes, that is sufficient. While working with the database, we want to expand this state. We are going to introduce a new IsActive parameter that will determine whether a person is shown on the screen. We don't need to change the implementation of IPersonState to add this capability; we are going to use an intersection type to handle this instead. The first thing we have to do is add a class that has this active flag and then create our intersection type:
export interface IRecordState {
IsActive : boolean;
}
export class RecordState implements IRecordState {
public IsActive: boolean;
}
export type PersonRecord = RecordState & IPersonState;