This commit is contained in:
Михаил Капелько
2024-01-29 18:09:14 +03:00
parent a0f8e2d31e
commit 49cee91239
106 changed files with 112 additions and 12 deletions

View File

@@ -0,0 +1,2 @@
var %NAME%: %TYPE% { get }
var %NAME%: MPAK.Recent<%TYPE%> { get }

View 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%
}
}

View File

@@ -0,0 +1,3 @@
Section%NAME%.destroyCore(self)
Section%NAME%.setupCore(self, ctrl, world)
SectionGenerated.setupPlatform(self, ctrl, world)

View 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%
}

View File

@@ -0,0 +1,5 @@
ctrl.m
.compactMap { %SHOULD%($0) }
.receive(on: DispatchQueue.main)
.sink { [weak core] v in %SINK% }
.store(in: &core.subscriptions)

View File

@@ -0,0 +1,4 @@
ctrl.m
.compactMap { %SHOULD%($0) }
.sink { [weak core] v in %SINK% }
.store(in: &core.subscriptions)

View File

@@ -0,0 +1,2 @@
let vm = VM()
var wnd: UIWindow?

View 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%
}
}

View File

@@ -0,0 +1,2 @@
public var %NAME%: %TYPE% = %DEFAULT%
public var %NAME%: MPAK.Recent<%TYPE%> = .init(%DEFAULT%)

View File

@@ -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)

View File

@@ -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
}
)

View File

@@ -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 }
)

View File

@@ -0,0 +1,13 @@
ctrl.%PIPE%(
dbg: "%SHORT_SRC%",
sub: %SUB%,
%SRC%.eraseToAnyPublisher(),
{ $0.%NAME% = $1 }
)

View File

@@ -0,0 +1,6 @@
Bus.events.compactMap { Bus.convertKeyValue(%BUS_KEY%, $0) }.map { (k: String, v: %BUS_VALUE_TYPE%) in v }

View File

@@ -0,0 +1,13 @@
ctrl.%PIPE%(
dbg: "%SHORT_SRC%",
sub: %SUB%,
%SRC%.eraseToAnyPublisher(),
{ $0.%NAME% = true },
{ $0.%NAME% = false }
)

View File

@@ -0,0 +1,13 @@
ctrl.%PIPE%(
dbg: "%SHORT_SRC%",
sub: %SUB%,
%SRC%.eraseToAnyPublisher(),
{ $0.%NAME% = $1 },
{ m, _ in m.%NAME% = nil }
)

View File

@@ -0,0 +1 @@
var core: Core?

View File

@@ -0,0 +1,2 @@
Section%NAME%.setupService(ctrl, self, world)
SectionGenerated.setupPlatform(ctrl, self, world)

View 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%
}

View File

@@ -0,0 +1,5 @@
ctrl.m
.compactMap { %SHOULD%($0) }
.receive(on: DispatchQueue.main)
.sink { v in %SINK% }
.store(in: &service.subscriptions)

View File

@@ -0,0 +1,3 @@
ctrl.m
.sink { v in Bus.send("%MODULE%", v) }
.store(in: &service.subscriptions)

View File

@@ -0,0 +1,4 @@
ctrl.m
.compactMap { %SHOULD%($0) }
.sink { v in %SINK% }
.store(in: &service.subscriptions)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
ctrl.m
.sink { v in world.model.send(v); modelRelay.send(v) }
.store(in: &service.subscriptions)

View File

@@ -0,0 +1,4 @@
modelRelay
.compactMap { %SHOULD%($0) }
.sink { v in %SINK% }
.store(in: &service.subscriptions)

View File

@@ -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)

View File

@@ -0,0 +1,4 @@
ctrl.m
.receive(on: DispatchQueue.main)
.sink { v in world.model.send(v) }
.store(in: &service.subscriptions)

View File

@@ -0,0 +1 @@
let modelRelay = PassthroughSubject<Model, Never>()

View File

@@ -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)

View File

@@ -0,0 +1 @@
self.%NAME% = %NAME%

View 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%

View File

@@ -0,0 +1,5 @@
_ %NAME%: %TYPE%
_ %NAME%: @escaping %TYPE%
_ %NAME%: AnyPublisher<%TYPE%, Never>
_ model: PassthroughSubject<%MODULE%.Model, Never>
_ net: @escaping () -> Net.Publisher