basic application state; basic subscriber and dispatcher
This commit is contained in:
parent
f5eed607bd
commit
a0580893c4
|
@ -2,7 +2,7 @@ import NimQml
|
|||
import status
|
||||
import libstatus
|
||||
import json
|
||||
|
||||
import state
|
||||
|
||||
var signalHandler: SignalCallback = proc(p0: cstring): void =
|
||||
setupForeignThreadGc()
|
||||
|
@ -37,7 +37,21 @@ QtObject:
|
|||
result.accountResult = status.queryAccounts()
|
||||
status.subscribeToTest()
|
||||
|
||||
var appState = state.newAppState()
|
||||
echo appState.title
|
||||
appState.subscribe(proc () =
|
||||
echo "1nd subscriber got a new update!"
|
||||
)
|
||||
|
||||
appState.addChannel("test")
|
||||
|
||||
appState.subscribe(proc () =
|
||||
echo "2nd subscriber got a new update!"
|
||||
)
|
||||
|
||||
appState.addChannel("test2")
|
||||
for channel in appState.channels:
|
||||
echo channel.name
|
||||
|
||||
# ¯\_(ツ)_/¯ dunno what is this
|
||||
proc setup(self: ApplicationLogic) =
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
|
||||
type Channel = object
|
||||
name*: string
|
||||
type
|
||||
Subscriber* = proc ()
|
||||
|
||||
type AppState* = ref object
|
||||
title*: string
|
||||
channels*: seq[Channel]
|
||||
subscribers*: seq[Subscriber]
|
||||
|
||||
proc newAppState*(): AppState =
|
||||
result = AppState(title: "hello")
|
||||
|
||||
proc subscribe*(self: AppState, subscriber: Subscriber) =
|
||||
self.subscribers.add(subscriber)
|
||||
|
||||
proc dispatch*(self: AppState) =
|
||||
for subscriber in self.subscribers:
|
||||
subscriber()
|
||||
|
||||
proc addChannel*(self: AppState, name: string) =
|
||||
self.channels.add(Channel(name: name))
|
||||
self.dispatch()
|
Loading…
Reference in New Issue