d
This commit is contained in:
2
Utilities/_platform/2/templates/context-field
Normal file
2
Utilities/_platform/2/templates/context-field
Normal file
@@ -0,0 +1,2 @@
|
||||
var %NAME%: %TYPE% { get }
|
||||
var %NAME%: MPAK.Recent<%TYPE%> { get }
|
||||
17
Utilities/_platform/2/templates/core
Normal file
17
Utilities/_platform/2/templates/core
Normal file
@@ -0,0 +1,17 @@
|
||||
// MARK: - Core
|
||||
|
||||
final class Core {
|
||||
%CORE_VM%
|
||||
var subscriptions = [AnyCancellable]()
|
||||
%CORE_WINDOW%
|
||||
|
||||
deinit {
|
||||
/**/aelog("😟 %MODULE_SHORT%Core.deinit")
|
||||
%CORE_SECTIONS_DESTROY%
|
||||
}
|
||||
|
||||
init(_ ctrl: %MODULE%.Controller, _ world: %MODULE%.World) {
|
||||
/**/aelog("😀 %MODULE_SHORT%Core.init")
|
||||
%CORE_SECTIONS_SETUP%
|
||||
}
|
||||
}
|
||||
3
Utilities/_platform/2/templates/core-section
Normal file
3
Utilities/_platform/2/templates/core-section
Normal file
@@ -0,0 +1,3 @@
|
||||
Section%NAME%.destroyCore(self)
|
||||
Section%NAME%.setupCore(self, ctrl, world)
|
||||
SectionGenerated.setupPlatform(self, ctrl, world)
|
||||
15
Utilities/_platform/2/templates/core-section-generated
Normal file
15
Utilities/_platform/2/templates/core-section-generated
Normal file
@@ -0,0 +1,15 @@
|
||||
// MARK: - SectionGenerated Core
|
||||
|
||||
static func setupPlatform(
|
||||
_ core: Core,
|
||||
_ ctrl: Controller,
|
||||
_ world: World
|
||||
) {
|
||||
// MARK: - SectionGenerated Core Actions
|
||||
|
||||
%CORE_SECTION_GENERATED_ACTIONS%
|
||||
|
||||
// MARK: - SectionGenerated Core Pipes
|
||||
|
||||
%CORE_SECTION_GENERATED_PIPES%
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
ctrl.m
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak core] v in %SINK% }
|
||||
.store(in: &core.subscriptions)
|
||||
@@ -0,0 +1,4 @@
|
||||
ctrl.m
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.sink { [weak core] v in %SINK% }
|
||||
.store(in: &core.subscriptions)
|
||||
2
Utilities/_platform/2/templates/core-window
Normal file
2
Utilities/_platform/2/templates/core-window
Normal file
@@ -0,0 +1,2 @@
|
||||
let vm = VM()
|
||||
var wnd: UIWindow?
|
||||
68
Utilities/_platform/2/templates/file
Normal file
68
Utilities/_platform/2/templates/file
Normal file
@@ -0,0 +1,68 @@
|
||||
// ВНИМАНИЕ Сгенерировано автоматом из файла %MODULE%.yml
|
||||
// ВНИМАНИЕ Не менять руками!
|
||||
|
||||
%IMPORTS%
|
||||
|
||||
// MARK: - Context
|
||||
|
||||
public protocol %MODULE%Context {
|
||||
%CONTEXT_FIELDS%
|
||||
}
|
||||
|
||||
// MARK: - Controller
|
||||
|
||||
extension %MODULE% {
|
||||
final class Controller: MPAK.Controller<%MODULE%.Model> {
|
||||
init() {
|
||||
super.init(
|
||||
%MODULE%.Model(),
|
||||
debugClassName: "%MODULE_SHORT%Ctrl",
|
||||
debugLog: { aelog($0) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
%CORE%
|
||||
|
||||
// MARK: - Model
|
||||
|
||||
public struct Model: %MODULE%Context {
|
||||
%MODEL_FIELDS%
|
||||
}
|
||||
|
||||
// MARK: - Service
|
||||
|
||||
public final class Service {
|
||||
let ctrl = Controller()
|
||||
let world: World
|
||||
%SERVICE_CORE%
|
||||
var subscriptions = [AnyCancellable]()
|
||||
static private(set) weak var singleton: Service?
|
||||
|
||||
public init(_ world: World) {
|
||||
self.world = world
|
||||
Self.singleton = self
|
||||
%SERVICE_SECTIONS%
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - World
|
||||
|
||||
public struct World {
|
||||
%WORLD_FIELDS%
|
||||
|
||||
public init(
|
||||
%WORLD_PARAMETERS%
|
||||
) {
|
||||
%WORLD_CONSTRUCTOR%
|
||||
}
|
||||
}
|
||||
|
||||
enum SectionGenerated {
|
||||
|
||||
%CORE_SECTION_GENERATED%
|
||||
|
||||
%SERVICE_SECTION_GENERATED%
|
||||
|
||||
}
|
||||
}
|
||||
2
Utilities/_platform/2/templates/model-field
Normal file
2
Utilities/_platform/2/templates/model-field
Normal file
@@ -0,0 +1,2 @@
|
||||
public var %NAME%: %TYPE% = %DEFAULT%
|
||||
public var %NAME%: MPAK.Recent<%TYPE%> = .init(%DEFAULT%)
|
||||
@@ -0,0 +1,8 @@
|
||||
ctrl.m
|
||||
.compactMap { shouldLoad%NAME%($0) }
|
||||
.flatMap { v -> AnyPublisher<Net.Result%NAME%, Never> in
|
||||
world.net().%REQUEST%(v).eraseToAnyPublisher()
|
||||
}
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { v in world.result%NAME%.send(v) }
|
||||
.store(in: &%SUB%.subscriptions)
|
||||
@@ -0,0 +1,13 @@
|
||||
ctrl.%PIPE%(
|
||||
dbg: "%SHORT_SRC%",
|
||||
sub: %SUB%,
|
||||
%SRC%.eraseToAnyPublisher(),
|
||||
{
|
||||
$0.%NAME%.value = $1
|
||||
$0.%NAME%.isRecent = true
|
||||
},
|
||||
{
|
||||
$0.%NAME%.isRecent = false
|
||||
$0.%EX_NAME% = $1
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
ctrl.%PIPE%(
|
||||
dbg: "%SHORT_SRC%",
|
||||
sub: %SUB%,
|
||||
%SRC%.eraseToAnyPublisher(),
|
||||
{
|
||||
$0.%NAME%.value = $1
|
||||
$0.%NAME%.isRecent = true
|
||||
},
|
||||
{ m, _ in m.%NAME%.isRecent = false }
|
||||
)
|
||||
|
||||
|
||||
|
||||
13
Utilities/_platform/2/templates/section-generated-pipe-set
Normal file
13
Utilities/_platform/2/templates/section-generated-pipe-set
Normal file
@@ -0,0 +1,13 @@
|
||||
ctrl.%PIPE%(
|
||||
dbg: "%SHORT_SRC%",
|
||||
sub: %SUB%,
|
||||
%SRC%.eraseToAnyPublisher(),
|
||||
{ $0.%NAME% = $1 }
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
Bus.events.compactMap { Bus.convertKeyValue(%BUS_KEY%, $0) }.map { (k: String, v: %BUS_VALUE_TYPE%) in v }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
ctrl.%PIPE%(
|
||||
dbg: "%SHORT_SRC%",
|
||||
sub: %SUB%,
|
||||
%SRC%.eraseToAnyPublisher(),
|
||||
{ $0.%NAME% = true },
|
||||
{ $0.%NAME% = false }
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
ctrl.%PIPE%(
|
||||
dbg: "%SHORT_SRC%",
|
||||
sub: %SUB%,
|
||||
%SRC%.eraseToAnyPublisher(),
|
||||
{ $0.%NAME% = $1 },
|
||||
{ m, _ in m.%NAME% = nil }
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1
Utilities/_platform/2/templates/service-core
Normal file
1
Utilities/_platform/2/templates/service-core
Normal file
@@ -0,0 +1 @@
|
||||
var core: Core?
|
||||
2
Utilities/_platform/2/templates/service-section
Normal file
2
Utilities/_platform/2/templates/service-section
Normal file
@@ -0,0 +1,2 @@
|
||||
Section%NAME%.setupService(ctrl, self, world)
|
||||
SectionGenerated.setupPlatform(ctrl, self, world)
|
||||
15
Utilities/_platform/2/templates/service-section-generated
Normal file
15
Utilities/_platform/2/templates/service-section-generated
Normal file
@@ -0,0 +1,15 @@
|
||||
// MARK: - SectionGenerated Service
|
||||
|
||||
static func setupPlatform(
|
||||
_ ctrl: Controller,
|
||||
_ service: Service,
|
||||
_ world: World
|
||||
) {
|
||||
// MARK: - SectionGenerated Service Actions
|
||||
|
||||
%SERVICE_SECTION_GENERATED_ACTIONS%
|
||||
|
||||
// MARK: - SectionGenerated Service Pipes
|
||||
|
||||
%SERVICE_SECTION_GENERATED_PIPES%
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
ctrl.m
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { v in %SINK% }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,3 @@
|
||||
ctrl.m
|
||||
.sink { v in Bus.send("%MODULE%", v) }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,4 @@
|
||||
ctrl.m
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.sink { v in %SINK% }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,5 @@
|
||||
ctrl.m
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.delay(for: .seconds(0.3), scheduler: RunLoop.main)
|
||||
.sink { v in %SINK% }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,3 @@
|
||||
ctrl.m
|
||||
.sink { v in world.model.send(v); modelRelay.send(v) }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,4 @@
|
||||
modelRelay
|
||||
.compactMap { %SHOULD%($0) }
|
||||
.sink { v in %SINK% }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,7 @@
|
||||
ctrl.m
|
||||
.compactMap { shouldResetCore($0) }
|
||||
.sink { v in
|
||||
service.core = v ? Core(ctrl, world) : nil
|
||||
world.isCoreRunning.send(v)
|
||||
}
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1,4 @@
|
||||
ctrl.m
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { v in world.model.send(v) }
|
||||
.store(in: &service.subscriptions)
|
||||
@@ -0,0 +1 @@
|
||||
let modelRelay = PassthroughSubject<Model, Never>()
|
||||
@@ -0,0 +1,8 @@
|
||||
ctrl.m
|
||||
.compactMap { shouldResetCore($0) }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { v in
|
||||
service.core = v ? Core(ctrl, world) : nil
|
||||
world.isCoreRunning.send(v)
|
||||
}
|
||||
.store(in: &service.subscriptions)
|
||||
1
Utilities/_platform/2/templates/world-constructor
Normal file
1
Utilities/_platform/2/templates/world-constructor
Normal file
@@ -0,0 +1 @@
|
||||
self.%NAME% = %NAME%
|
||||
7
Utilities/_platform/2/templates/world-field
Normal file
7
Utilities/_platform/2/templates/world-field
Normal file
@@ -0,0 +1,7 @@
|
||||
let %NAME%: %TYPE%
|
||||
let %NAME% = CurrentValueSubject<%TYPE%, Never>(%DEFAULT%)
|
||||
let %NAME%: AnyPublisher<%TYPE%, Never>
|
||||
let model: PassthroughSubject<%MODULE%.Model, Never>
|
||||
let net: () -> Net.Publisher
|
||||
let %NAME% = PassthroughSubject<%TYPE%, Never>()
|
||||
var %NAME%: %TYPE% = %DEFAULT%
|
||||
5
Utilities/_platform/2/templates/world-parameter
Normal file
5
Utilities/_platform/2/templates/world-parameter
Normal file
@@ -0,0 +1,5 @@
|
||||
_ %NAME%: %TYPE%
|
||||
_ %NAME%: @escaping %TYPE%
|
||||
_ %NAME%: AnyPublisher<%TYPE%, Never>
|
||||
_ model: PassthroughSubject<%MODULE%.Model, Never>
|
||||
_ net: @escaping () -> Net.Publisher
|
||||
Reference in New Issue
Block a user