This file contains 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
channels$: Observable<Channel[]>; | |
selectedChannel$: Observable<Channel>; | |
constructor(public channelService: ChannelService) { | |
this.channels$ = channelService.channelsChanged$; | |
this.selectedChannel$ = channelService.selectedChannel$; | |
} |
This file contains 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
private channelSubject$ = new BehaviorSubject<Channel[]>([]); | |
private get channels(): Channel[] { | |
return this.channelSubject$.getValue(); | |
} | |
private set channels(val: Channel[]) { | |
this.channelSubject$.next(val); | |
} |
This file contains 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
var lastDoc: QueryDocumentSnapshot? | |
var listeners: [ListenerRegistration] = [] | |
var query: Query = db.collection("channels").document("the doc id for this channel").collection("messages").limit(to: 25) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
addListener() // adds listener for first 25 messages | |
} | |
func scrollViewDidScroll(_ scrollView: UIScrollView) { |
This file contains 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
let privateContext = CoreDataStack.generatePrivateContext() | |
// 1. | |
privateContext.perform { | |
// 2. | |
for userJSON in jsonResponse { | |
let id = user["id"] as! Int | |
// 3. | |
self.searchUserBy(id: 0, in: privateContext) { (user) in |
This file contains 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
static func searchUserBy(id: Int, in context: NSManagedObjectContext, completionHandler: @escaping (_ managedObjects: User?) -> Void) { | |
context.perform { | |
//searching core data | |
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "User") | |
request.returnsObjectsAsFaults = false | |
request.predicate = NSPredicate(format: "id == %@", "\(id)") | |
do { | |
let results = try context.fetch(request) | |
if let managedObjects = results as? [NSManagedObject], let user = managedObjects.first { |
This file contains 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
class CoreDataHelper { | |
// MARK: - Core Data Stack | |
lazy var applicationDocumentsDirectory: URL = { | |
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
return urls[urls.count-1] | |
}() | |
lazy var managedObjectModel: NSManagedObjectModel = { |
This file contains 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
var express = require('express'); | |
var app = express(); | |
const Realm = require('realm'); | |
// realm set up | |
const adminUser = Realm.Sync.User.adminUser('**'); | |
var token = "***"; | |
Realm.Sync.setAccessToken(token); | |
const AppointmentSchema = { |
This file contains 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
console.log("Starting function"); | |
const Realm = require('realm'); | |
const adminUser = Realm.Sync.User.adminUser('**') | |
const server_url = 'realm://**'; | |
module.exports = function(changeEvent) { | |
console.log('Change detected at path: ' + changeEvent.path); | |
const changes = changeEvent.changes["UserSearch"]; |
This file contains 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
Logs: | |
Starting function | |
Changes in realm at: /globalUsers | |
Changes in Model: GlobalUser | |
- object inserted at position 4 : RealmObject { username: 'test', email: '[email protected]' } | |
Code: | |
console.log("Starting function"); | |
// add your initialization code here |
This file contains 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
'use strict' | |
const moment = require('moment'); | |
const Realm = require('realm'); | |
// these two lines were copied and pasted from the email sent me after registering for the free trial | |
var token = "***"; | |
Realm.Sync.setAccessToken(token); | |
// TODO: make this admin key an environmental variable |