You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/12/08 02:20:25 UTC

[royale-docs] branch master updated: beginnings of code conventions

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/royale-docs.git


The following commit(s) were added to refs/heads/master by this push:
     new efe971c  beginnings of code conventions
efe971c is described below

commit efe971c76e6a17b35c9de6bddd5fc64a96bb06e3
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri Dec 7 18:20:10 2018 -0800

    beginnings of code conventions
---
 Create An Application.md                  |  2 +-
 create-an-application/code-conventions.md | 81 ++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/Create An Application.md b/Create An Application.md
index 7177e82..5eee4e2 100644
--- a/Create An Application.md	
+++ b/Create An Application.md	
@@ -33,4 +33,4 @@ This document is divided into several sections:
 
 [Modules](create-an-application/modules.html) discusses how to break your application into pieces so it doesn't have to all get downloaded at once.  Or have the whole thing compiled at once.
 
-[Royale code conventions](create-an-application/royale-code-conventions.html) explains the typical ways Royale developers name files, classes, function, variables and more.
+[Royale code conventions](create-an-application/code-conventions.html) explains the typical ways Royale developers name files, classes, function, variables and more.
diff --git a/create-an-application/code-conventions.md b/create-an-application/code-conventions.md
index 3dcc8c7..a28429f 100644
--- a/create-an-application/code-conventions.md
+++ b/create-an-application/code-conventions.md
@@ -20,4 +20,83 @@ title: Royale code conventions
 
 # Royale code conventions
 
-*This information will be available soon.*
+Warning:  This document is not complete.
+
+## Packages
+
+Packages have lower.case.names separated by periods if needed.  MixedCase names starting with lower case is ok, but short package names are preferred so that you aren't tempted to mixCase.
+
+## Classes
+
+Classes have MixedCase names starting with a capital letter (and no hyphens)
+
+## Constants
+
+Constants have CAPITALIZED_NAMES separated by underscore '_'
+
+## Properties
+
+Properties have mixedCase names starting with a lower case letter
+
+## Events
+
+Events have mixedCase names starting with a lower case letter
+
+## Event Classes
+
+Where Apache Flex had lots of event classes, Royale strives to have as few as possible, since each class has download overhead.  Royale has an Event which has an event name in the "type" field and no other payload.  A ValueEvent contains one item that might be of interest to the listener.  ValueChangeEvent has oldValue/newValue.  There may be a StringEvent and other 'typed' event classes.
+
+Event constants go in the Class that will dispatch the event.  Thus the developer only has to import one class and to write the code.
+
+The reason behind this change is partly because JavaScript runtimes aren't really going to type-check the event instance.  Royale has code that will do the type-checking, but it is pretty rare to have to discriminate between event classes.  So it is best to turn off the type-checking code in Royale.
+
+To compare:
+
+### Flex
+
+```
+public class TimerEvent {
+  public const TIMER:String = "timer";
+}
+
+public class Timer {
+   dispatchEvent(new TimerEvent(TimerEvent.TIMER));
+}
+```
+Usage:
+```
+import TimerEvent;
+import Timer;
+
+var timer:Timer = new Timer();
+timer.addEventListener(TimerEvent.TIMER, timerHandler);
+
+function timerHandler(event:TimerEvent):void
+{
+}
+```
+
+### Royale
+
+```
+public class Timer {
+   public const TIMER:String = "timer";
+   dispatchEvent(new Event(TIMER));
+}
+```
+
+Usage:
+
+```
+import Timer;
+
+var timer:Timer = new Timer();
+timer.addEventListener(Timer.TIMER, timerHandler);
+
+function timerHandler(event:Event):void
+{
+}
+```
+
+
+