Hey there! I’ve just started using Hype coming from a web development background and I am loving it!
One feature that I would love to see is being able to add in custom arguments to javascript functions that are used in Hype. I think it would greatly increase the power and flexibilty of combining JS with animations.
Right now I haven’t been able to find a good way to reuse functions across elements, like I would coding in javascript, and instead, I have to create a whole new function with the same code
For example, if I want to create a piano with different notes on each using javascript, I have to create several different functions that are essentially the exact same.
playNoteC(hypeDocument, element, event) { play('c') }
playNoteD(hypeDocument, element, event) { play['d') }
playNoteE(hypeDocument, element, event) {play('e') }
This gets tedious, and now imagine if you wanted to add functionality like logging what key was pressed to each of the keys, I would have to then go in each function and update one at a time with the new logic.
As a programmer, I would expect something like
function playNote(hypeDocument, element, event, customArgument) {
play(customArgument)
}
And from there I would be able to copy and paste the same object in hype, and just add/change arguments for the function on an event. Then On click->run Javascript Function->playNote()->withCustomArgument(‘C’)
Maybe there is already a way to achieve this in Hype that I am unaware of, but if not, I think it would be awessomeeee. You could then even pass in callbacks and functions as arguments and boost the flexibility. For example, if I wanted a function that made a server request to save state data, and then to play a melody on the hypothetical piano I could do something like.
On click -> run Javascript function saveSate()
->with argument ( function playSound() )
-> with argument( ‘C’)
The function would then look something like, where the callback can be used when the Ajax call succeeds.
function saveSate(hypeDocument, element, event, customArgument) {
//Blah blah some ajax call syntax
$.ajax({
type: "POST",
success: customArgument(),
});
}
Thanks! Obviously this is just a sample implementation, and y’all would know best, but I would die to be able to have this as a more modular programming platform!