This commit is contained in:
Михаил Капелько
2024-01-08 17:45:45 +03:00
parent aa203c2337
commit e8f330ad2a
12 changed files with 47 additions and 12 deletions

View File

@@ -1,10 +1,17 @@
from generation.isPipeMany import *
from generation.isPipeRecent import *
def fieldFormat(fmtPlain, fmtRecent, name, structure):
def fieldFormat(fmtMany, fmtPlain, fmtRecent, name, structure):
fmt = fmtPlain
if (
isPipeRecent(name, structure.core) or
isPipeRecent(name, structure.service)
):
fmt = fmtRecent
if (
isPipeMany(name, structure.core) or
isPipeMany(name, structure.service)
):
fmt = fmtMany
return fmt

View File

@@ -5,11 +5,12 @@ def generateContextFields(c):
lines = c.readFile(fileName)
fmtPlain = lines[0]
fmtRecent = lines[1]
fmtMany = lines[2]
fields = []
for key in c.structure.model.fields:
values = c.structure.model.fields[key]
fmt = fieldFormat(fmtPlain, fmtRecent, key, c.structure)
fmt = fieldFormat(fmtMany, fmtPlain, fmtRecent, key, c.structure)
ln = fmt \
.replace("%NAME%", key) \
.replace("%TYPE%", values[0])

View File

@@ -5,11 +5,12 @@ def generateModelFields(c):
lines = c.readFile(fileName)
fmtPlain = lines[0]
fmtRecent = lines[1]
fmtMany = lines[2]
fields = []
for key in c.structure.model.fields:
values = c.structure.model.fields[key]
fmt = fieldFormat(fmtPlain, fmtRecent, key, c.structure)
fmt = fieldFormat(fmtMany, fmtPlain, fmtRecent, key, c.structure)
ln = fmt \
.replace("%NAME%", key) \
.replace("%TYPE%", values[0]) \

View File

@@ -0,0 +1,5 @@
def isPipeMany(name, entity):
if name in entity.pipes:
props = entity.pipes[name]
return "many" in props
return False

View File

@@ -1,5 +1,11 @@
from generation.isPipeMany import *
def pipeBusSource(name, entity, busKey, structure, fmt):
valueType = structure.model.fields[name][0]
if isPipeMany(name, entity):
itemType = structure.model.fields[key][0]
valueType = f"MPAK.Many<{itemType}>"
return fmt \
.replace("%BUS_KEY%", busKey) \
.replace("%BUS_VALUE_TYPE%", valueType)

View File

@@ -1,6 +1,8 @@
def pipeFormat(fmtExRecent, fmtRecent, fmtSet, fmtToggle, fmtToggleNil, name, entity):
def pipeFormat(fmtExRecent, fmtMany, fmtRecent, fmtSet, fmtToggle, fmtToggleNil, name, entity):
props = entity.pipes[name]
if "recent" and "ex" in props:
if "many" in props:
return fmtMany
elif "recent" and "ex" in props:
return fmtExRecent
elif "recent" in props:
return fmtRecent

View File

@@ -6,6 +6,7 @@ from generation.pipeSource import *
def sectionGeneratedPipes(entity, sub, c):
fmtBusPipe = c.readFile(f"{c.dir}/templates/section-generated-pipe-src-bus")[0]
fmtExRecent = c.readFile(f"{c.dir}/templates/section-generated-pipe-ex-recent")
fmtMany = c.readFile(f"{c.dir}/templates/section-generated-pipe-many")
fmtRecent = c.readFile(f"{c.dir}/templates/section-generated-pipe-recent")
fmtSet = c.readFile(f"{c.dir}/templates/section-generated-pipe-set")
fmtToggle = c.readFile(f"{c.dir}/templates/section-generated-pipe-toggle")
@@ -33,7 +34,7 @@ def sectionGeneratedPipes(entity, sub, c):
if src.startswith("K."):
src = pipeBusSource(key, entity, src, c.structure, fmtBusPipe)
fmtPipe = pipeFormat(fmtExRecent, fmtRecent, fmtSet, fmtToggle, fmtToggleNil, key, entity)
fmtPipe = pipeFormat(fmtExRecent, fmtMany, fmtRecent, fmtSet, fmtToggle, fmtToggleNil, key, entity)
for fmt in fmtPipe:
ln = fmt \
.replace("%EX_NAME%", exName) \

View File

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

View File

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

View File

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

View File

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