From cd214e888e296941d53b0ebadbc5421208fe33c3 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Fri, 5 Apr 2019 01:29:10 -0600 Subject: [PATCH] Added docs for the task bloc --- lib/src/blocs/new_image_bloc.dart | 8 ++++---- lib/src/blocs/task_bloc.dart | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/src/blocs/new_image_bloc.dart b/lib/src/blocs/new_image_bloc.dart index 8e21002..142f766 100644 --- a/lib/src/blocs/new_image_bloc.dart +++ b/lib/src/blocs/new_image_bloc.dart @@ -26,7 +26,7 @@ class NewImageBloc { /// A subject of the current user model. final _user = BehaviorSubject(); - /// A subject of the current task event name. + /// A subject of the current media event name. final _eventName = BehaviorSubject(); NewImageBloc() { @@ -40,10 +40,10 @@ class NewImageBloc { /// An observable of the user model. Observable get userModelStream => _user.stream; - /// An observable of the task event name. + /// An observable of the media event name. Observable get eventName => _eventName.stream; - /// An observable of the ready to submit flag. + /// An observable of the submit enabled flag. Observable get submitEnabled => Observable.combineLatest2(_picture, _eventName, (a, b) => true); @@ -51,7 +51,7 @@ class NewImageBloc { /// Changes the current picture file. Function(File) get changePicture => _picture.sink.add; - /// Changes the current task event name. + /// Changes the current media event name. Function(String) get changeEventName => _eventName.sink.add; /// Fetches and updates the current user. diff --git a/lib/src/blocs/task_bloc.dart b/lib/src/blocs/task_bloc.dart index c6a68ac..d982511 100644 --- a/lib/src/blocs/task_bloc.dart +++ b/lib/src/blocs/task_bloc.dart @@ -9,39 +9,66 @@ import '../resources/firestore_provider.dart'; import '../services/auth_service.dart'; import '../services/current_task_service.dart'; +/// Business logic component that manages the state for the task screen. class TaskBloc extends Object with Validators { + /// An instance of the auth service. final AuthService _auth = authService; + + /// An instance of the firebase repository. final FirestoreProvider _firestore = firestoreProvider; + + /// An instance of the current task service. final CurrentTaskService _taskService = currentTaskService; + + /// A subject of user model. final _user = BehaviorSubject(); + + /// A subject of task event name. final _eventName = BehaviorSubject(); + + /// A subject of task text. final _taskText = BehaviorSubject(); + + /// The priority of the current task. TaskPriority priority = TaskPriority.high; + /// The text of the current global task. String get textInitialValue => _taskService.task.text; //Stream getters. + /// An observable of the current user model. Observable get userModelStream => _user.stream; + + /// An observable of the current task event name. Observable get eventName => _eventName.stream; + + /// An observable of the current task text. Observable get taskText => _taskText.stream.transform(validateStringNotEmpty); + + /// An observable of the submit enabled flag. Observable get submitEnabled => Observable.combineLatest2(eventName, taskText, (a, b) => true); //Sinks getters. + /// Changes the current task event name. Function(String) get changeEventName => _eventName.sink.add; + + ///Changes the current task text. Function(String) get changeTaskText => _taskText.sink.add; TaskBloc() { setCurrentUser(); } + /// Changes the current task priority. void setPriority(TaskPriority newPriority) { priority = newPriority; } //TODO: Figure out how to update the event and user properties if needed. + /// Saves or updates the current task in the database. Future submit(isEdit) { if (isEdit) { return _firestore.updateTask( @@ -60,12 +87,15 @@ class TaskBloc extends Object with Validators { return _firestore.addTask(newTask); } + /// Fetches and updates the current user. Future setCurrentUser() async { final user = await _auth.currentUser; final userModel = await _firestore.getUser(username: user.email); _user.add(userModel); } + /// Grabs the data from the current global task and pipes it to the local + /// streams. void populateWithCurrentTask() { TaskModel currentTask = _taskService.task; if (currentTask != null) {