This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Tuple, Dict, Any, Union | |
from channels.db import database_sync_to_async | |
from django.core.exceptions import ObjectDoesNotExist | |
from ..models import QuizSession, QuizParticipant, Answer, QuizSessionQuestion, UserAnswer | |
from ..models.multiplayer_models import MultiplayerSession | |
from ..serializers import FirebaseUserSerializer, QuizParticipantSerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from datetime import datetime | |
import json | |
from channels.generic.websocket import AsyncWebsocketConsumer | |
from channels.db import database_sync_to_async | |
from django.core.exceptions import ObjectDoesNotExist | |
import logging | |
import time | |
from django.db import transaction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Combine | |
class CombineController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
@IBOutlet weak var emptyView: UIView! | |
@IBOutlet weak var activityIndicator: UIActivityIndicatorView! | |
lazy var viewModel: CombineViewModel = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire | |
import Combine | |
class CombineViewModel: ObservableObject { | |
var apiManager: APIManager? | |
@Published var employees: [Employee] = [] //1 | |
init(manager: APIManager = APIManager()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import RxCocoa | |
class RxSwiftController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
@IBOutlet weak var emptyView: UIView! | |
@IBOutlet weak var activityIndicator: UIActivityIndicatorView! | |
let disposeBag = DisposeBag() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire | |
import RxSwift | |
import RxCocoa | |
class RxSwiftViewModel { | |
private let disposeBag = DisposeBag() | |
private let _employees = BehaviorRelay<[Employee]>(value: []) | |
private let _error = BehaviorRelay<Bool>(value: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********* Binding to array in viewDidLoad */ | |
viewModel.employees.bind { (_) in | |
self.showTableView() | |
} | |
/********************************/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupEventBusSubscriber() { | |
_ = EventBus.onMainThread(self, name: "fetchEmployees") { result in | |
if let event = result!.object as? EmployeesEvent { | |
if event.employees != nil { | |
self.showTableView() | |
} else if let message = event.errorMessage { | |
self.showAlert(title: "Error", message: message) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func callEvent() { | |
//Post Event (Publish Event) | |
EventBus.post("fetchEmployees", sender: EmployeesEvent(error: error, errorMessage: errorMessage, employees: employees)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class EmployeesEvent: NSObject { | |
var error: Bool | |
var errorMessage: String? | |
var employees: [Employee]? | |
init(error: Bool, errorMessage: String? = nil, employees: [Employee]? = nil) { | |
self.error = error | |
self.errorMessage = errorMessage |
NewerOlder