Skip to content

Commit

Permalink
Merge pull request #507 from Kitware/fix-proxy-ui-hanling
Browse files Browse the repository at this point in the history
fix(proxy): Properly handle ui section
  • Loading branch information
jourdain authored Jan 18, 2018
2 parents 0f645ff + 425811c commit d1d93ea
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Sources/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function getCurrentGlobalMTime() {
/* eslint-disable no-prototype-builtins */

const fakeConsole = {};

function noOp() {}

const consoleMethods = [
Expand Down Expand Up @@ -122,7 +123,9 @@ export function obj(publicAPI = {}, model = {}) {
function unsubscribe() {
off(index);
}
return Object.freeze({ unsubscribe });
return Object.freeze({
unsubscribe,
});
}

publicAPI.isDeleted = () => !!model.deleted;
Expand Down Expand Up @@ -723,7 +726,9 @@ export function event(publicAPI, model, eventName) {
function unsubscribe() {
off(callbackID);
}
return Object.freeze({ unsubscribe });
return Object.freeze({
unsubscribe,
});
}

function invoke() {
Expand Down Expand Up @@ -895,9 +900,13 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
model.proxyId = `${nextProxyId++}`;
publicAPI.getProxyId = () => model.proxyId;

// ui handling
const ui = JSON.parse(JSON.stringify(uiDescription)); // deep copy

// group properties
const propertyMap = {};
const groupChildrenNames = {};

function registerProperties(descriptionList, currentGroupName) {
if (!groupChildrenNames[currentGroupName]) {
groupChildrenNames[currentGroupName] = [];
Expand All @@ -907,7 +916,6 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
for (let i = 0; i < descriptionList.length; i++) {
childrenNames.push(descriptionList[i].name);
propertyMap[descriptionList[i].name] = descriptionList[i];

if (descriptionList[i].children && descriptionList[i].children.length) {
registerProperties(
descriptionList[i].children,
Expand All @@ -916,14 +924,12 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
}
}
}
registerProperties(uiDescription, ROOT_GROUP_NAME);
registerProperties(ui, ROOT_GROUP_NAME);

// list
publicAPI.listProxyProperties = (gName = ROOT_GROUP_NAME) =>
groupChildrenNames[gName];

// ui handling
const ui = uiDescription.map((i) => Object.assign({}, i));
publicAPI.updateProxyProperty = (propertyName, propUI) => {
const prop = propertyMap[propertyName];
if (prop) {
Expand Down Expand Up @@ -967,15 +973,21 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
updateInProgress = true;
while (needUpdate.length) {
const linkToUpdate = needUpdate.pop();
linkToUpdate.instance.set({ [linkToUpdate.propertyName]: value });
linkToUpdate.instance.set({
[linkToUpdate.propertyName]: value,
});
}
updateInProgress = false;
}
}

function bind(instance, propertyName) {
const subscription = instance.onModified(update);
links.push({ instance, propertyName, subscription });
links.push({
instance,
propertyName,
subscription,
});
}

function unbind(instance, propertyName) {
Expand All @@ -999,7 +1011,11 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
}
}

const linkHandler = { bind, unbind, unsubscribe };
const linkHandler = {
bind,
unbind,
unsubscribe,
};
model.propertyLinkMap[id] = linkHandler;
return linkHandler;
};
Expand All @@ -1013,7 +1029,11 @@ export function proxy(publicAPI, model, sectionName, uiDescription = []) {
const name = propertyNames[i];
const method = publicAPI[`get${capitalize(name)}`];
const value = method ? method() : undefined;
const prop = { id, name, value };
const prop = {
id,
name,
value,
};
const children = getProperties(name);
if (children.length) {
prop.children = children;
Expand Down

0 comments on commit d1d93ea

Please sign in to comment.