-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for ES6 script classes #1908
Add support for ES6 script classes #1908
Conversation
# Conflicts: # src/script/script.js
…ce when needed instead of relying on pc.createScript.
I'm good, only have few things to be clarified before merging:
|
|
Some things to take note of:
I can't test custom engine with editor IDE in browser to actually see how the ES6 intellisense thing behaves . But from the code itself, since it extends the ScriptType class, it shouldn't have any intellisense issues with regards to that. Just got to remember to call "registerScript" at the end (or use a decorator for that) to register the script into playcanvas. |
@Glidias Thank you for the comment.
Agreed. Ideally, there would be a |
Decorators though would require custom babel settings and such since it's an experimental feature , so I don't think it can be a built in feature even though technically the method could still be included as a seperate module file (or then again, it's possibly just a one-liner importable decorator method anyway) for optional use. On a sidenote, I have some fancy @attrib decorators I used in some of my babel/webpack integration examples for ES6 (mainly TypeScript) classes (you can check my repos). But again, all these are just syntax sugar that can only work in certain build/config environments. (Not forgetting that there is a certain functional call overhead, though likely negligible, when using such decorators). |
@Glidias I've fixed the issue with |
* stable: (48 commits) [RELEASE] v1.26.0 [FIX] null access when pushing SpectorJS marker without camera (playcanvas#1933) [FIX] pc.XrHitTest when WebXR not available Update package-lock.json Downgrade mocha to 6.2.2 WebXR AR hit test support (playcanvas#1926) [ImgBot] Optimize images (playcanvas#1927) [DOCS] Make anim API private (playcanvas#1924) Update NPM dependencies. [FIX] Update some example paths Update to latest JSDoc template [FIX] Updating of particle systems local bounds Add pc.drawTexture to render texture to target using a shader (playcanvas#1920) Optimize Grab-Pass for WebGL 2 and fix when using anti-aliased RenderTarget (playcanvas#1918) [DOCS] Document drawQuadWithShader and copyRenderTarget (playcanvas#1919) [FIX] Mouse wheel events on elements (playcanvas#1916) glTF 2.0 support (playcanvas#1904) Update to latest JSDoc template. Add support for ES6 script classes (playcanvas#1908) Particle system randomize sprite animations (playcanvas#1911) ...
Fixes #1907 (also #1889 and #1887).
PR consists of the following significant changes:
pc.ScriptType
andpc.ScriptAttributes
frompc.createScript()
(and move into own filesscript-type.js
andscript-attributes.js
).pc.ScriptType
andpc.ScriptAttributes
to work as regular standalone public classes (instead of imaginary types existing only in the docs). Also makingpc.ScriptType
possible to extend in ES6.pc.registerScript()
to register ES6 script classes (which doesn't needpc.createScript()
). Includes full documentation and example.pc.createScript()
to use newpc.registerScript()
,pc.ScriptType
, andpc.ScriptAttributes
and keep backward-compatibility.pc.ScriptType
class itself, instead of the instance (see issuesScriptType
Typescript typing is being used for both script types and their instances? #1889 and Type hinting ofScriptType
created withpc.createScript
within prototypes #1887). Requires jsdoc template fix: Add "typeof" support for referencing a class type itself (not only the instance) playcanvas-jsdoc-template#8 (make sure template package is updated with fix).Using the PR devs can now choose between either regular ES5-style or ES6-class scripts:
ES5 example:
ES6 example:
All changes have been tested using a public PlayCanvas project (simply run it with and without the PR):
With PR:
Without PR:
I confirm I have signed the Contributor License Agreement.