Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MAKI functions that need input, implement popupmenu #854

Merged
merged 9 commits into from
Aug 17, 2019

Conversation

jberg
Copy link
Collaborator

@jberg jberg commented Aug 15, 2019

No description provided.

@@ -1,5 +1,9 @@
import { xml2js } from "xml-js";

export function isPromise(obj) {
return "function" == typeof obj.then;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d swap the order of these and use ===.

https://en.m.wikipedia.org/wiki/Yoda_conditions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

let val = gen.next();
while (!val.done) {
val = gen.next();
if (val.value && isPromise(val.value)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just make isPromise support nullable values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was debating whether it should or not, guess it kinda looks like it should hah

stack.push(obj[methodName](...methodArgs));
const ret = obj[methodName](...methodArgs);
if (ret && isPromise(ret)) {
stack.push(yield ret);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break the debugger? If so, we can fix in a subsequent PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think it would break the debugger right now

@@ -15,6 +15,8 @@ function useJsUpdates(node) {
useEffect(() => node.js_listen("js_update", forceUpdate));
}

let mouseposition;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how we want to do this. We need to keep track of the mouse position for some things, but the mousedown events get spammed, and I dont think the changes affect rendering. How do we want to store these?

@@ -295,7 +312,8 @@ export function* interpret(start, program, stack = []) {
case 96: {
const classesOffset = command.arg;
const Klass = classes[classesOffset];
const klassInst = new Klass();
const system = variables[0].getValue();
const klassInst = new Klass(null, system.scriptGroup);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are kind of abusing the MAKI object notion of a parent to get a reference to the scriptGroup in Maki Objects incase they need to do something related to the MAKI tree they have a reference

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable hack. I wonder if we can find an experiment that will tell us what the parent of a created object is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that's a bit odd here (and I guess is intentional) is that we end up with a node that has another node as its parent but that parent does not have the new node as a child.

All of this will get reconsidered when (if?) we switch to Redux, so I'm okay leaving it as is for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable hack. I wonder if we can find an experiment that will tell us what the parent of a created object is.

Yea that would be great. PopupMenu is really bizarre because it never actually gets added to any object in the MAKI script, it just gets created and then later popAtMouse runs, so it really doesn't seem to have any parent.

And yea, the tree structure gets kinda weird. hopefully we'll have better ideas of how to do it in the future :D

@jberg jberg marked this pull request as ready for review August 16, 2019 08:26
@jberg jberg force-pushed the handle-maki-functions-needing-input branch from 80f3313 to 7220c88 Compare August 16, 2019 16:39
@jberg jberg changed the title Handle MAKI functions that need input Handle MAKI functions that need input, implement popupmenu Aug 16, 2019
</li>
);
});
const { x, y } = mouseposition;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this with a useEffect that listens for the document mousemove event and then calls a local setState. If it happens too frequently, we can throttle it.

top: Number(y),
left: Number(x),
backgroundColor: "#000000",
color: "#FFFFFF",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some // TODO comment here noting that we should come back to this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -295,7 +312,8 @@ export function* interpret(start, program, stack = []) {
case 96: {
const classesOffset = command.arg;
const Klass = classes[classesOffset];
const klassInst = new Klass();
const system = variables[0].getValue();
const klassInst = new Klass(null, system.scriptGroup);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable hack. I wonder if we can find an experiment that will tell us what the parent of a created object is.

// Interpret is a generator that yields before each command is exectued.
// `handler` is reponsible for `.next()`ing until the program execution is
// complete (the generator is "done"). In production this is done
// synchronously. In the debugger, if execution is paused, it's done
// async.
debugHandler(interpret(commandOffset, program, args.reverse()));
await debugHandler(interpret(commandOffset, program, args.reverse()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to await here? I think it would be fine to return form this function without waiting for the promise to resolve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops. tested it and we do not need it, thanks!

}

hide() {
this.visible = false;
this.parent.js_trigger("js_update");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -10,7 +10,7 @@ class MakiObject {
} else {
// When dynamically creating an object with `new` we have no underlying node
this.attributes = {};
this.name = this.constructor.name.toLowerCase();
this.name = this.getclassname().toLowerCase();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -67,7 +71,7 @@ class MakiObject {
* @ret The class name.
*/
getclassname() {
return "Object";
return "MakiObject";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp. Thanks!

super(node, parent);

this.commands = [];
this.resolveCmdSelection = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are private properties right? Can they start with _?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh whoops, they are actually referenced in the rendering. I will rename the resolve function with a js_ prefix though

@@ -295,7 +312,8 @@ export function* interpret(start, program, stack = []) {
case 96: {
const classesOffset = command.arg;
const Klass = classes[classesOffset];
const klassInst = new Klass();
const system = variables[0].getValue();
const klassInst = new Klass(null, system.scriptGroup);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that's a bit odd here (and I guess is intentional) is that we end up with a node that has another node as its parent but that parent does not have the new node as a child.

All of this will get reconsidered when (if?) we switch to Redux, so I'm okay leaving it as is for now.

@jberg jberg merged commit 067d4c1 into captbaritone:master Aug 17, 2019
captbaritone pushed a commit that referenced this pull request Nov 30, 2019
* initial test for generator class functions

* return promise from functions that need async

* move null check into isPromise and fix condition

* implementing popmenu

* fix dynamic node creation in prod build

* remove unnecessary async/await

* rename function with js_ prefix

* TODO to fix styles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants