i need remove ctx stranger

This commit is contained in:
Leifer Mendez
2022-11-19 21:07:41 +01:00
parent 7cf013e52b
commit 4879df040f
8 changed files with 140 additions and 51 deletions

View File

@@ -1,19 +1,55 @@
const { toSerialize } = require('./methods')
class FlowClass {
flow
allContexts = []
allCallbacks = []
flowSerialize = []
flowRaw = []
constructor(_flow) {
this.flow = toSerialize(_flow)
if (!Array.isArray(_flow)) throw new Error('Esto debe ser un ARRAY')
_flow.forEach((ctxFlow, parentIndex) => {
const callbacks = ctxFlow.ctx?.callbacks || []
const contexts = ctxFlow.ctx?.contexts || []
callbacks.forEach((deepCallbacks) => {
if (deepCallbacks && contexts[parentIndex]) {
const ctxChild = contexts[parentIndex]
deepCallbacks.callback(null, ctxChild)
}
})
})
this.flowRaw = _flow
this.allContexts = _flow
.map((ctxs) => ctxs.ctx.contexts)
.flat(2)
.map((c, i) => ({ getCtx: c?.getCtx, index: i }))
this.allCallbacks = _flow
.map((cbIn) => cbIn.ctx.callbacks)
.flat(2)
.map((c, i) => ({ callback: c?.callback, index: i }))
const mergeToJsonSerialize = Object.keys(_flow)
.map((indexObjectFlow) => _flow[indexObjectFlow].toJson())
.flat(2)
this.flowSerialize = toSerialize(mergeToJsonSerialize)
}
find = (keyOrWord, symbol = false) => {
let capture = false
let messages = []
let refSymbol
let refSymbol = null
const findIn = (keyOrWord, symbol = false, flow = this.flow) => {
const findIn = (
keyOrWord,
symbol = false,
flow = this.flowSerialize
) => {
capture = refSymbol?.options?.capture || false
if (capture) return messages
if (symbol) {
refSymbol = flow.find((c) => c.keyword === keyOrWord)
if (refSymbol?.answer) messages.push(refSymbol)
@@ -29,7 +65,9 @@ class FlowClass {
}
findBySerialize = (refSerialize) =>
this.flow.find((r) => r.refSerialize === refSerialize)
this.flowSerialize.find((r) => r.refSerialize === refSerialize)
findIndexByRef = (ref) => this.flowSerialize.findIndex((r) => r.ref === ref)
}
module.exports = FlowClass