improve action hint behavior

This commit is contained in:
Val Erastov 2018-01-26 19:47:52 -08:00
parent 8396629277
commit 8d06e86708
4 changed files with 42 additions and 30 deletions

View file

@ -75,6 +75,8 @@ export default class Bus {
}
dispatch(key, data) {
console.log('dispatch: ' + key + ' -> ' + JSON.stringify(data));
if (this.lock.has(key)) {
console.warn('recursive dispatch');
return

View file

@ -4,9 +4,35 @@ export function mapActionBehavior(actionIdProp) {
return ({dispatch}, props) => {
const actionId = props[actionIdProp];
const actionRunToken = ACTION_TOKENS.actionRun(actionId);
let request = {actionId, x:0, y:0};
let canceled = true;
let showed = false;
function updateCoords({pageX, pageY}) {
request.x = pageX + 10;
request.y = pageY + 10;
}
return {
onClick: data => dispatch(actionRunToken, data),
onMouseEnter: ({pageX, pageY}) => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, [actionId, pageX, pageY]),
onMouseLeave: () => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, null)
onMouseEnter: e => {
updateCoords(e);
canceled = false;
showed = false;
setTimeout(() => {
if (!canceled) {
showed = true;
dispatch(ACTION_TOKENS.SHOW_HINT_FOR, request)
}
}, 500);
},
onMouseMove: updateCoords,
onMouseLeave: () => {
canceled = true;
if (showed) {
dispatch(ACTION_TOKENS.SHOW_HINT_FOR, null)
}
}
}};
}
}

View file

@ -59,35 +59,18 @@ export function activate(context) {
function synchActionHint(bus) {
let lastRequest = null;
// bus.subscribe(TOKENS.REQUEST_SHOW_HINT_FOR
bus.subscribe(TOKENS.SHOW_HINT_FOR, request => {
if (lastRequest !== null) {
if (request !== null) {
if (request[0] === lastRequest[0]) {
Object.assign(lastRequest, request);
return;
}
}
lastRequest.spoiled = true;
}
lastRequest = request;
if (request) {
setTimeout(() => {
if (!request.spoiled) {
let [actionId, x, y] = request;
let actionState = bus.getState(TOKENS.actionState(actionId));
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
if (actionState && actionAppearance) {
bus.dispatch(TOKENS.HINT, {
actionId, x: x + 10, y: y + 10,
info: actionAppearance.info,
hint: actionState.hint
});
}
}
}, 500);
let {actionId, x, y} = request;
let actionState = bus.getState(TOKENS.actionState(actionId));
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
if (actionState && actionAppearance) {
bus.dispatch(TOKENS.HINT, {
actionId, x, y,
info: actionAppearance.info,
hint: actionState.hint
});
}
} else {
bus.dispatch(TOKENS.HINT, null);
}

View file

@ -1,3 +1,4 @@
.root {
display: flex;
pointer-events:none;
}