-
Notifications
You must be signed in to change notification settings - Fork 640
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
Handle MAKI functions that need input, implement popupmenu #854
Conversation
modern/src/utils.js
Outdated
@@ -1,5 +1,9 @@ | |||
import { xml2js } from "xml-js"; | |||
|
|||
export function isPromise(obj) { | |||
return "function" == typeof obj.then; |
There was a problem hiding this comment.
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 ===
.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
80f3313
to
7220c88
Compare
</li> | ||
); | ||
}); | ||
const { x, y } = mouseposition; |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp. Thanks!
modern/src/runtime/PopupMenu.js
Outdated
super(node, parent); | ||
|
||
this.commands = []; | ||
this.resolveCmdSelection = null; |
There was a problem hiding this comment.
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 _
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, thanks!
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
* 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
No description provided.