店舗parttenを実装するとき、我々は突然変異に注意する必要があります。
クラスデータストア{ プライベートレッスン:レッスン[] = []; プライベートlessonsSubjectは = 新しいSubjectImplementationを(); lessonsLists $:観測 = { (OBS){購読 この.lessonsSubject.subscribe(OBS)を、 obs.next(レッスン); }、 退会(OBS){ この.lessonsSubject.unsubscribe(OBS)。 }、 }。 initializeLessonsList(newList:レッスン[]){ この .lessons = _.cloneDeep(newList)。 この.lessonsSubject.next(レッスン); } addLessons(newLessons){ この.lessons.push(_ cloneDeep(newLessons)。)。//は深いクローン作成 この .lessonsSubject.nextを(この.lessons)。 } } エクスポートCONSTストア = 新しいデータストア()。
私たちは、偶然の変異を避けるために、深いクローンを作成する必要があります。