Skip to content

Commit

Permalink
🧰🎨: deprecate viewModel.withoutExposedPropsDo()
Browse files Browse the repository at this point in the history
any of the stuff that we used withoutExposedPropsDo() for can now be used more uniformly with the getter setter overriding via bindings.
  • Loading branch information
merryman authored and linusha committed Jul 3, 2024
1 parent 35984e9 commit c634d07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
27 changes: 17 additions & 10 deletions lively.ide/debug/console.cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,18 @@ class LocalJSConsoleModel extends ViewModel {
static get properties () {
return {
logLimit: { defaultValue: 1000 },
bindings: {
get () {
return [
{ signal: 'keybindings', override: true, handler: 'keybindings' },
{ signal: 'commands', override: true, handler: 'commands' },
{ signal: 'menuItems', override: true, handler: 'menuItems' }
];
}
},
expose: {
get () {
return ['onWindowClose', 'clear', 'commands', 'menuItems', 'keybindings'];
return ['onWindowClose', 'clear'];
}
}
};
Expand Down Expand Up @@ -230,27 +239,25 @@ class LocalJSConsoleModel extends ViewModel {
if (!test) this.error('Assert failed: ' + msg);
}

get keybindings () {
const viewKeybindings = this.withoutExposedPropsDo(() => this.view.keybindings);
keybindings ({ get: viewKeybindings }) {
return [
{ keys: { mac: 'Meta-K', win: 'Ctrl-Alt-K' }, command: '[console] clear' },
...viewKeybindings
{ keys: { mac: 'Meta-Alt-K', win: 'Ctrl-Alt-K' }, command: '[console] clear' },
...viewKeybindings()
];
}

get commands () {
const viewCommands = this.withoutExposedPropsDo(() => this.view.commands);
commands ({ get: viewCommands }) {
return [
{
name: '[console] clear',
exec: () => { this.clear(); return true; }
},
...viewCommands
...viewCommands()
];
}

async menuItems () {
const viewItems = await this.withoutExposedPropsDo(() => this.view.menuItems());
async menuItems ($super) {
const viewItems = await $super();
return [
{ command: '[console] clear', target: this, alias: 'clear' },
{ isDivider: true },
Expand Down
18 changes: 0 additions & 18 deletions lively.morphic/components/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,24 +524,6 @@ export class ViewModel {
}
}

/**
* Invoke the given callback function without the viewModel exposing any props.
* In case the function is asynchronous, the bindings will be disabled as long as the function needs to terminate.
* @param { function } cb - The function to invoke while the bindings are disabled.
* @return { } - The value returned by `cb`.
*/
withoutExposedPropsDo (cb) {
this.clearExposedProps();
let res;
try {
res = cb();
} catch (err) {
console.error(err.message);
}
if (res && res.then) { return res.then(() => { this.reifyExposedProps(); return res; }); } else this.reifyExposedProps();
return res;
}

disableBindings () {
this.getBindingConnections().forEach(conn => conn.deactivate());
}
Expand Down

0 comments on commit c634d07

Please sign in to comment.