From 5f128075417082a9602425bf4946a5dca0fe6a29 Mon Sep 17 00:00:00 2001 From: eff-kay Date: Fri, 7 May 2021 13:08:29 -0400 Subject: [PATCH] :construction: temp fix --- dash-renderer/src/APIController.react.js | 1 + dash-renderer/src/TreeContainer.js | 2 + dash-renderer/src/actions/callbacks.ts | 3 + dash-renderer/src/actions/dependencies_ts.ts | 98 ++++++++++++++++++- dash-renderer/src/actions/index.js | 15 ++- .../src/observers/prioritizedCallbacks.ts | 2 + .../src/observers/requestedCallbacks.ts | 7 ++ 7 files changed, 122 insertions(+), 6 deletions(-) diff --git a/dash-renderer/src/APIController.react.js b/dash-renderer/src/APIController.react.js index fe939774f1..813b60bd7f 100644 --- a/dash-renderer/src/APIController.react.js +++ b/dash-renderer/src/APIController.react.js @@ -117,6 +117,7 @@ const UnconnectedContainer = props => { }; function storeEffect(props, events, setErrorLoading) { + const { appLifecycle, dependenciesRequest, diff --git a/dash-renderer/src/TreeContainer.js b/dash-renderer/src/TreeContainer.js index 28d5936e78..4213b13428 100644 --- a/dash-renderer/src/TreeContainer.js +++ b/dash-renderer/src/TreeContainer.js @@ -126,6 +126,8 @@ class BaseTreeContainer extends Component { (val, key) => !equals(val, oldProps[key]), newProps ); + + console.log("props", newProps, "old", oldProps); if (!isEmpty(changedProps)) { // Identify the modified props that are required for callbacks const watchedKeys = getWatchedKeys( diff --git a/dash-renderer/src/actions/callbacks.ts b/dash-renderer/src/actions/callbacks.ts index 7bb917f189..4e7a9e43f8 100644 --- a/dash-renderer/src/actions/callbacks.ts +++ b/dash-renderer/src/actions/callbacks.ts @@ -450,6 +450,7 @@ export function executeCallback( try { const inVals = fillVals(paths, layout, cb, inputs, 'Input', true); + console.log('ACTIONS: executing CB', cb) /* Prevent callback if there's no inputs */ if (inVals === null) { return { @@ -530,6 +531,8 @@ export function executeCallback( executionPromise: __promise }; + console.log('ACTIONS: Executed CB done', cb) + return newCb; } catch (error) { return { diff --git a/dash-renderer/src/actions/dependencies_ts.ts b/dash-renderer/src/actions/dependencies_ts.ts index 0314f4f1ad..6b8ba44784 100644 --- a/dash-renderer/src/actions/dependencies_ts.ts +++ b/dash-renderer/src/actions/dependencies_ts.ts @@ -1,8 +1,10 @@ import { all, assoc, + call, concat, difference, + F, filter, flatten, forEach, @@ -16,6 +18,7 @@ import { reduce, zipObj } from 'ramda'; +import callbacks from '../reducers/callbacks'; import { ICallback, ICallbackProperty, @@ -40,6 +43,55 @@ export const mergeMax = mergeWith(Math.max); export const combineIdAndProp = ({id, property}: ICallbackProperty) => `${stringifyId(id)}.${property}`; +// for everycallback returned, +// check if the relevant callback is in the callback path of the thing + +//TODO: override the interface for this, compare the signatures +function isSimilar(paths:any, callbackA:ICallback, callbackB:ICallback):boolean{ + + const outputsA = flatten(callbackA.getOutputs(paths)); + const inputsA = flatten(callbackA.getInputs(paths)); + + const outputsB = flatten(callbackB.getOutputs(paths)); + const inputsB = flatten(callbackB.getInputs(paths)); + + return (JSON.stringify(inputsA)==JSON.stringify(inputsB) && JSON.stringify(outputsA)&&JSON.stringify(outputsB)) ? true: false; +} + +export function callbackPathExists(graphs:any, paths:any, fromCallback:ICallback, toCallback:ICallback): boolean { + + // check for base condition + if (isSimilar(paths, fromCallback, toCallback)) { + console.log('CALLDAG:callbackPathExists match found'); + return true; + } + + const outputs = flatten(fromCallback.getOutputs(paths)); + console.log('CALLDAG:callbackPathExists outputs', outputs); + + const callbacks = + flatten(map( + ({id, property}: any) => { + return graphs.inputMap[id][property]; + }, + outputs + )) + + if (!callbacks.length){ + //we have reached the end of the DAG + return false; + } + + const matches: ICallback[] = []; + callbacks.forEach( + addAllResolvedFromOutputs(resolveDeps(), paths, matches) + ); + + const exists = matches.some((cb)=>{return callbackPathExists(graphs, paths, cb, toCallback)}) + console.log('CALLDAG:callbackPathExists callbacks',exists); + return exists; +} + export function getCallbacksByInput( graphs: any, paths: any, @@ -51,6 +103,8 @@ export function getCallbacksByInput( const matches: ICallback[] = []; const idAndProp = combineIdAndProp({id, property: prop}); + console.log("CALLDAG:getCallBackByInput:inputs ID", id, "PROP", prop); + if (typeof id === 'string') { // standard id version const callbacks = (graphs.inputMap[id] || {})[prop]; @@ -58,15 +112,20 @@ export function getCallbacksByInput( return []; } + console.log("CALLDAG:getCallBackByInput callbacks", callbacks); + callbacks.forEach( addAllResolvedFromOutputs(resolveDeps(), paths, matches) ); + + console.log("CALLDAG:getCallBackByInput callbacks afterOutputs", callbacks, "matches", matches); } else { // wildcard version const _keys = Object.keys(id).sort(); const vals = props(_keys, id); const keyStr = _keys.join(','); const patterns: any[] = (graphs.inputPatterns[keyStr] || {})[prop]; + if (!patterns) { return []; } @@ -82,12 +141,16 @@ export function getCallbacksByInput( } }); } + matches.forEach(match => { match.changedPropIds[idAndProp] = changeType || DIRECT; if (withPriority) { match.priority = getPriority(graphs, paths, match); } }); + + console.log("CALLDAG:getCallBackByInput callbacks matches with priority", matches); + return matches; } @@ -117,6 +180,8 @@ export function getPriority( outputs ); + console.log("CALLDAG:getPriority callback outputs", outputs); + callbacks = flatten( map( ({id, property}: any) => @@ -131,6 +196,7 @@ export function getPriority( outputs ) ); + console.log("CALLDAG:getPriority callbacks after flattening", callbacks); if (callbacks.length) { priority.push(callbacks.length); @@ -253,18 +319,46 @@ export const getUniqueIdentifier = ({ Array.isArray(anyVals) ? anyVals : anyVals === '' ? [] : [anyVals] ).join(','); + export function includeObservers( id: any, properties: any, graphs: any, paths: any ): ICallback[] { - return flatten( + + + console.log('CALLDAG:includeObservers properties', properties, keys(properties)); + + let func = (propName)=>{ + let cbs = getCallbacksByInput(graphs, paths, id, propName); + console.log("CALLDAG:includeObservers callback", cbs); + return cbs; + } + + const flattenedCbs = flatten( map( - propName => getCallbacksByInput(graphs, paths, id, propName), + (propName)=> func(propName), keys(properties) ) ); + + var validCbs = [... flattenedCbs]; + + //TODO: not sure if this is optimal + // for(let i=0; i = { dispatch ); + console.log("prioritizedCallBack: cb executing", executingCallback) + dispatch( aggregateCallbacks([ removeBlockedCallbacks([cb]), diff --git a/dash-renderer/src/observers/requestedCallbacks.ts b/dash-renderer/src/observers/requestedCallbacks.ts index 2b1cd1dc0e..f5f1c19c1f 100644 --- a/dash-renderer/src/observers/requestedCallbacks.ts +++ b/dash-renderer/src/observers/requestedCallbacks.ts @@ -68,10 +68,14 @@ const observer: IStoreObserverDefinition = { callbacks: {requested} } = getState(); + + console.log("observer:requestedCallbacks: requested", requested); + const initialRequested = requested.slice(0); const pendingCallbacks = getPendingCallbacks(callbacks); + console.log("observer:requestedCallbacks: pending", pendingCallbacks); /* 0. Prune circular callbacks that have completed the loop - cb.callback included in cb.predecessors @@ -374,6 +378,9 @@ const observer: IStoreObserverDefinition = { const added = difference(requested, initialRequested); const removed = difference(initialRequested, requested); + + + console.log("requestedCallbacks: added", added, "removed", removed); dispatch( aggregateCallbacks([