render ctx
This commit is contained in:
1 parent
fbea0673c1
commit
fbb02855ee
10 files changed
+167
-15
No files matched your search
@@ -4,6 +4,8 @@ final class AppDelegate:
|
||||
NSObject,
|
||||
NSApplicationDelegate
|
||||
{
|
||||
let render = RenderComponent()
|
||||
let renderVM = RenderVM()
|
||||
let root = RootComponent()
|
||||
let rootVM = RootVM()
|
||||
|
||||
@@ -14,6 +16,8 @@ final class AppDelegate:
|
||||
|
||||
otherSetupConsoleLogging(root.ctrl, "Root")
|
||||
root.setup()
|
||||
otherSetupConsoleLogging(render.ctrl, "Render")
|
||||
render.setup()
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
|
||||
@@ -124,8 +124,63 @@ public struct F {
|
||||
public static let didClickIncrement = "didClickIncrement"
|
||||
public static let didLaunch = "didLaunch"
|
||||
public static let didSetup = "didSetup"
|
||||
public static let isReadyToRender = "isReadyToRender"
|
||||
public static let pixelHeight = "pixelHeight"
|
||||
public static let pixelWidth = "pixelWidth"
|
||||
|
||||
}
|
||||
public struct RenderContext: DialectContext {
|
||||
public var didLaunch = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var isReadyToRender = Bool()
|
||||
public var pixelHeight = Int()
|
||||
public var pixelWidth = Int()
|
||||
|
||||
public var recentField = ""
|
||||
|
||||
public func field<T>(_ name: String) -> T {
|
||||
if (name == "didLaunch") {
|
||||
return didLaunch as! T
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
return didSetup as! T
|
||||
}
|
||||
else if (name == "isReadyToRender") {
|
||||
return isReadyToRender as! T
|
||||
}
|
||||
else if (name == "pixelHeight") {
|
||||
return pixelHeight as! T
|
||||
}
|
||||
else if (name == "pixelWidth") {
|
||||
return pixelWidth as! T
|
||||
}
|
||||
|
||||
return "unknown-field-name" as! T
|
||||
}
|
||||
|
||||
public mutating func setField(
|
||||
_ name: String,
|
||||
_ value: Any
|
||||
) {
|
||||
if (name == "didLaunch") {
|
||||
didLaunch = value as! Bool
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
didSetup = value as! Bool
|
||||
}
|
||||
else if (name == "isReadyToRender") {
|
||||
isReadyToRender = value as! Bool
|
||||
}
|
||||
else if (name == "pixelHeight") {
|
||||
pixelHeight = value as! Int
|
||||
}
|
||||
else if (name == "pixelWidth") {
|
||||
pixelWidth = value as! Int
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public struct RootContext: DialectContext {
|
||||
public var count = Int()
|
||||
public var countText = String()
|
||||
@@ -178,6 +233,13 @@ public struct RootContext: DialectContext {
|
||||
}
|
||||
}
|
||||
|
||||
public func renderSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
) {
|
||||
RenderComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
public func rootSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
@@ -185,6 +247,24 @@ public func rootSet(
|
||||
RootComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Only once during the first setup */
|
||||
if
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
{
|
||||
c.didLaunch = true
|
||||
c.recentField = F.didLaunch
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func rootShouldResetCount(_ c: RootContext) -> RootContext {
|
||||
var c = c
|
||||
|
||||
@@ -256,6 +336,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext {
|
||||
return c
|
||||
}
|
||||
|
||||
func renderRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
renderShouldResetDidLaunch,
|
||||
|
||||
].forEach { f in
|
||||
ctrl.registerFunction { c in f(c as! RenderContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func rootRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
rootShouldResetCount,
|
||||
@@ -267,9 +356,15 @@ func rootRegisterShoulds(_ ctrl: DialectController) {
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RenderContext? = registerOneliners(ctrl, [
|
||||
F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") },
|
||||
|
||||
])
|
||||
}
|
||||
|
||||
func rootRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RootContext? = registerOneliners(ctrl, [
|
||||
F.countText, { (c: RootContext) in print(c.countText) },
|
||||
F.countText, { (c: RootContext) in RootVM.shared!.countText = c.countText },
|
||||
|
||||
])
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../../components/render/render.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../components/render/renderConst.swift
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../../components/render/renderVM.swift
|
||||
Reference in new issue
Block a user