mirror of https://github.com/iSoron/uhabits.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
50 lines
1.0 KiB
import Foundation
|
|
|
|
@objc(CoreModule)
|
|
class CoreModule: RCTEventEmitter {
|
|
|
|
@objc
|
|
open override func supportedEvents() -> [String] {
|
|
return ["onHabitList"]
|
|
}
|
|
|
|
@objc
|
|
func requestHabitList() {
|
|
DispatchQueue.main.async {
|
|
let habits = AppDelegate.backend.getHabitList()
|
|
let result = habits.map {
|
|
["key": String($0.key.intValue),
|
|
"name": $0.value["name"],
|
|
"color": $0.value["color"]]
|
|
}
|
|
self.sendEvent(withName: "onHabitList", body: result)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
func createHabit(_ name: String) {
|
|
DispatchQueue.main.async {
|
|
AppDelegate.backend.createHabit(name: name)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
func deleteHabit(_ id: Int32) {
|
|
DispatchQueue.main.async {
|
|
AppDelegate.backend.deleteHabit(id: id)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
func updateHabit(_ id: Int32, _ name: String) {
|
|
DispatchQueue.main.async {
|
|
AppDelegate.backend.updateHabit(id: id, name: name)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
override static func requiresMainQueueSetup() -> Bool {
|
|
return true
|
|
}
|
|
}
|