Good first question.
Typedefs represent a JS Library's API. When the browser loads in the
ace.js file, new methods and APIs will be available. You should create a
Typedefs SWC for that API. IIRC, ace.js creates a global object called
"ace" that you would want to call from your ACEEditor.as.
In their example [1] there are lines of code like this:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
If you compile this in Royale as-is, on the first line, the compiler will
complain that there is no type specified for "var editor", and there is no
function or object called "ace". So the point of the Typedefs is to
define the classes and methods that the ACE folks would have written if
they had written their code in AS instead of JS. And thus, keep the
compiler from complaining and catch mistakes in your code. So you might
define an ace.as for a TypeDefs SWC that looks like::
package {
public class ace()
{
public static function edit(id:String):ace {}
public function setTheme(theme:String):void;
...
}
}
Bonus points for making constants for the string literals like
"ace/theme/monokai".
Then the code in ACEEditor.as can look more like AS:
var editor:ace = ace.edit(id);
//editor.setTheme("ace/theme/monokai");
editor.setTheme(ace.THEME_MONOKAI); // bonus points for making this work
because it eliminates typos.
...
Harbs mentioned that you don't "have to" create a Typedefs SWC. You could
write the AS code like this:
Var editor:Object = window["ace"].edit(id);
editor.setTheme("ace/theme/monokai");
...
But that isn't type-safe AS. You could mistype a lot of things in that
snippet and the compiler won't catch it.
IMO, all of the code in [1] should end up in your ACEEditor.as so folks
can do the typical Royale thing for UI widgets such as:
MXML: <ace:ACEEditor id="foo" width="100%" height="300"/>
AS: var aceEditor:ACEEditor = new ACEEditor();
aceEditor.id = foo;
...
addElement(aceEditor);
We want these patterns to be the patterns for declaring or dynamically
creating any and every UI widget (Button, DataGrid, etc) so folks don't
have to learn a new pattern per component.
So the challenge for you is to make it all work.
HTH,
-Alex
[1] https://ace.c9.io/#nav=embedding
On 1/3/18, 11:21 PM, "Olaf Krueger" <[email protected]> wrote:
>One first question comes into my mind:
>
>We have TypeDefs and Royale components.
>In case of providing the Ace editor as Royale component, should we still
>provide an separate AS3 class or interface as TypeDef in the TypeDef repo
>that represents the JS API?
>
>Or should the needed API be part of the ACEEditor class (which extends
>UIBase) without having an separate TypeDef interface?
>
>My first idea is to create the TypeDef as an AS3 interface e.g.
>IACEEditor.as which has to be implemented by ACEEditor.as.
>
>Thanks,
>Olaf
>
>
>
>--
>Sent from:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-roy
>ale-development.20373.n8.nabble.com%2F&data=02%7C01%7Caharui%40adobe.com%7
>Cfc355b181bf543671de008d55343da8c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7
>C0%7C636506473261178766&sdata=ytzlNQ5TxLGdrb5f0fUxuiiwFTe0dZ%2BqdJS39guL93
>0%3D&reserved=0