class MainViewModel:

    def __init__(self):
        self.note_repository = NoteRepository()
        # Create notes field as a behavior subject with note from the business logic as an initial value
        # Your code here
        self.observables = []

    def attach(self, observable):
        self.observables.append(observable)
        observable.update_view(self.note_repository.notes)

    def add_note(self, note: str):
        # Add note and emit event with new date to the subject
        # Your code here
        self.note_repository.add_note(note)
        for o in self.observables:
            o.update_view(self.note_repository.notes)

    def clear_all(self):
        # Clear all note and emit event with new data to the subject
        # Your code here
        self.note_repository.clear_all_notes()
        for o in self.observables:
            o.update_view(self.note_repository.notes)
예제 #2
0
class MainViewModel:
    def __init__(self):
        self.note_repository = NoteRepository()
        # Create notes field as a behavior subject with note from the business logic as an initial value
        # Your code here
        self.behavior = BehaviorSubject(self.note_repository.get_all_notes())

    def add_note(self, note: str):
        # Add note and emit event with new date to the subject
        # Your code here
        self.note_repository.add_note(note)
        self.behavior.on_next(self.note_repository.get_all_notes())

    def clear_all(self):
        # Clear all note and emit event with new data to the subject
        # Your code here
        self.note_repository.clear_all_notes()
        self.behavior.on_next(self.note_repository.get_all_notes())