Skip to content

Commit

Permalink
🚧 temp fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eff-kay committed May 11, 2021
1 parent edce374 commit 5f12807
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 6 deletions.
1 change: 1 addition & 0 deletions dash-renderer/src/APIController.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const UnconnectedContainer = props => {
};

function storeEffect(props, events, setErrorLoading) {

const {
appLifecycle,
dependenciesRequest,
Expand Down
2 changes: 2 additions & 0 deletions dash-renderer/src/TreeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions dash-renderer/src/actions/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -530,6 +531,8 @@ export function executeCallback(
executionPromise: __promise
};

console.log('ACTIONS: Executed CB done', cb)

return newCb;
} catch (error) {
return {
Expand Down
98 changes: 96 additions & 2 deletions dash-renderer/src/actions/dependencies_ts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {
all,
assoc,
call,
concat,
difference,
F,
filter,
flatten,
forEach,
Expand All @@ -16,6 +18,7 @@ import {
reduce,
zipObj
} from 'ramda';
import callbacks from '../reducers/callbacks';
import {
ICallback,
ICallbackProperty,
Expand All @@ -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,
Expand All @@ -51,22 +103,29 @@ 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];
if (!callbacks) {
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 [];
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -117,6 +180,8 @@ export function getPriority(
outputs
);

console.log("CALLDAG:getPriority callback outputs", outputs);

callbacks = flatten(
map(
({id, property}: any) =>
Expand All @@ -131,6 +196,7 @@ export function getPriority(
outputs
)
);
console.log("CALLDAG:getPriority callbacks after flattening", callbacks);

if (callbacks.length) {
priority.push(callbacks.length);
Expand Down Expand Up @@ -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<validCbs.length; i++) {
// for (let j=i+1; j<validCbs.length; j++) {
// if (callbackPathExists(graphs, paths, validCbs[i], flattenedCbs[j])) {
// //path exists remove the extra cb
// validCbs.splice(j,1);
// }
// }
// }

console.log('CALLDAG:includeObservers: validCbs', validCbs);

return validCbs;

}

/*
Expand Down
15 changes: 11 additions & 4 deletions dash-renderer/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cookie from 'cookie';
import {validateCallbacksToLayout} from './dependencies';
import {includeObservers, getLayoutCallbacks} from './dependencies_ts';
import {getPath} from './paths';
import callbacks from '../reducers/callbacks';

export const onError = createAction(getAction('ON_ERROR'));
export const setAppLifecycle = createAction(getAction('SET_APP_LIFECYCLE'));
Expand Down Expand Up @@ -65,12 +66,15 @@ function triggerDefaultState(dispatch, getState) {
})
);
}
let callbacks = getLayoutCallbacks(graphs, paths, layout, {
outputsOnly: true
})

console.log('CALLDAG:triggerDefaultState getLayoutCallbacks', callbacks)

dispatch(
addRequestedCallbacks(
getLayoutCallbacks(graphs, paths, layout, {
outputsOnly: true
})
callbacks
)
);
}
Expand Down Expand Up @@ -102,10 +106,13 @@ function moveHistory(changeType) {
}

export function notifyObservers({id, props}) {
console.log(':notifyObservers, updating observers', props);
return async function(dispatch, getState) {
const {graphs, paths} = getState();
let callbacks = includeObservers(id, props, graphs, paths)
console.log('CALLDAG: notification', callbacks)
dispatch(
addRequestedCallbacks(includeObservers(id, props, graphs, paths))
addRequestedCallbacks(callbacks)
);
};
}
Expand Down
2 changes: 2 additions & 0 deletions dash-renderer/src/observers/prioritizedCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ const observer: IStoreObserverDefinition<IStoreState> = {
dispatch
);

console.log("prioritizedCallBack: cb executing", executingCallback)

dispatch(
aggregateCallbacks([
removeBlockedCallbacks([cb]),
Expand Down
7 changes: 7 additions & 0 deletions dash-renderer/src/observers/requestedCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ const observer: IStoreObserverDefinition<IStoreState> = {
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
Expand Down Expand Up @@ -374,6 +378,9 @@ const observer: IStoreObserverDefinition<IStoreState> = {

const added = difference(requested, initialRequested);
const removed = difference(initialRequested, requested);


console.log("requestedCallbacks: added", added, "removed", removed);

dispatch(
aggregateCallbacks([
Expand Down

0 comments on commit 5f12807

Please sign in to comment.