Skip to content
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

ES6 class definition & module support #915

Open
obiot opened this issue Jan 11, 2018 · 12 comments
Open

ES6 class definition & module support #915

obiot opened this issue Jan 11, 2018 · 12 comments
Milestone

Comments

@obiot
Copy link
Member

@obiot obiot commented Jan 11, 2018

This ticket list all the related tasks required to migrate to es6 and using a module approach. Until fully stable, the current build process will however keep transpiling everything to es5 and generate a es5 umd module. Ultimately the goal is to generate two different build :

  • melonjs.js legacy es5 build for legacy browsers/devices (to be decided yet at which level we keep some backward compatibility with regard to the current Jay inheritance mechanism vs a standard es5 here)
  • melons-module.js a es6 module based version for modern browser/devices (use es6 inheritance mechanism)

Migration phases :

  • ES6 class semantic : to replace the current Jay inheritance mechanism (see also #685) :

    • me.Object
    • me.Ellipse : -> me.Object
    • me.Pointer (used by me.input) : -> me.Object
    • me.Rect : -> me.Polygon
    • me.Polygon : -> me.Object
    • me.Line : -> me.Polygon
    • me.Renderable : -> me.Object
    • me.Camera2d : -> me.Renderable
    • me.Sprite : -> me.Renderable
    • me.ColorLayer : -> me.Renderable
    • me.ImageLayer : -> me.Renderable
    • me.GUI : -> me.Renderable
    • me.Body : -> me.Rect
    • me.Entity (deprecated in version 9.0) : -> me.Renderable
    • me.Text : -> me.Renderable
    • me.BitmapText : -> me.Renderable
    • me.BitmapTextData (only used by me.BitmapText) : -> me.Renderable
    • me.Container : -> me.Renderable
    • me.Stage : -> me.Renderable
  • ES6 module export : to allow generating a es6 bundle:

    • Class definition
      • me.Object
      • me.Renderable
      • me.Sprite
      • me.ColorLayer
      • me.ImageLayer
      • me.GUI
      • me.Entity (deprecated in version 9.0)
      • me.Text
      • me.BitmapText
      • me.BitmapTextData (only used by me.BitmapText)
      • me.Container
      • me.Stage
      • me.Vector2d
      • me.Vector3d
      • me.ObservableVector2d
      • me.ObservableVector3d
      • me.Matrix2d
      • me.Matrix3d
      • me.Camera2d
      • me.TMX(xxxx)
      • me.ParticleContainer (only used by me.ParticleEmmiter)
      • me.ParticleEmmiter
      • me.Particle
      • me.Body
      • me.Quadtree
      • me.Ellipse
      • me.Pointer (used by me.input)
      • me.Rect
      • me.Polygon
      • me.Line
      • me.Tween
      • me.Color
      • me.Renderer
      • me.Rendere.Texture
      • TextureCache (private)
      • me.CanvasRenderer
      • me.WebGLRenderer
      • me.GLShader
      • me.WebGLCompositor
    • built-in utility class (changes to es6 will be backward compatible)
      • me
      • me.audio
      • me.event
      • me.input
      • me.levelDirector (-> me.level)
      • me.loader
      • me.Math
      • me.collision
      • me.plugin
      • me.state
      • me.agent (-> me.utils.agent)
      • me.device
      • me.pool
      • me.save
      • me.timer
      • me.utils.*
      • me.video
      • me.game
      • me.sys (remove/deprecated)
  • ES6 module support : with potential option to build tailored version of melonJS with only selected modules -> structure and build process in place, rest will be done gradually while converting the above class definition to es6

  • deprecated API : include this automatically in the build process only once (after) the transpiling to es5

  • [#678] window.fetch : might not be that widely supported, but a polyfill can easily be added, see https://github.com/github/fetch

  • Babylon Rollup Bubble : to automatically transpile and generate an ES5 build.

I will close all the ticket referenced in this one, just to avoid having the same topic covered in different places.

Feel free to comments here under !

@obiot obiot added this to the 6.0.0 milestone Jan 11, 2018
obiot added a commit that referenced this issue Jan 21, 2018
new me.Math api that will grow along with other items removed from native objects.
obiot added a commit that referenced this issue Jan 23, 2018
and keep removing polyfill not required since the mimimum browswer requirement as listed on the website.
obiot added a commit that referenced this issue Jan 27, 2018
obiot added a commit that referenced this issue Jan 27, 2018
@itsjavi
Copy link
Contributor

@itsjavi itsjavi commented Feb 23, 2018

Oh I am really looking forward for v6
I am currently doing nasty things in order to use Melon with Webpack and Babel as you can see: https://github.com/pokettomonstaa/NewBark

Thank you for taking care of this!

@SnareChops
Copy link

@SnareChops SnareChops commented May 26, 2018

@obiot How can I help move this along? I would really like to use your game engine over Phaser due to the simplicity this provides, but non es6 and non npm available makes it extremely difficult to use with typescript. I have a large amount of time I could commit to moving this project along, and only need a quick pointer to get started (ie. "Can you start converting these files" / "This is the next goal ____ start here")

@obiot
Copy link
Member Author

@obiot obiot commented May 28, 2018

@SnareChops Well I would looooove some help on this to be honest, I've been side tracked recently, and this is taking much longer than I initially expected...

In terms of progress though I almost converted all the classes to the ES6 syntax, what is missing is a few of them, and the whole build process that also need to be updated. So if you really have a lots of free time and want to help you can start by looking at the below branch and either finish converting the classes definition and/or update the build process (for the converted classes) + run one of the example against it :
https://github.com/melonjs/melonJS/tree/ES6-update

Can't thank you enough in advance for any help you can provide on this one :)

As for the master branch, I was planning (will do so shortly) to release an intermediate release with the current changes that includes cleaning of the API (to ensure melonJS is properly isolated within its own namesake) and all the bug fixes from the 5.x branch.

@obiot obiot modified the milestones: 6.0.0, 7.0.0 Jun 1, 2018
@obiot obiot changed the title melonJS 6.0.0 : ES6 & others melonJS 7.0.0 : ES6 & others Jun 1, 2018
@kibertoad
Copy link
Contributor

@kibertoad kibertoad commented Jul 4, 2018

@obiot So what's the plan for the ES6 branch for now? Is it going to be synced with master at some point? Also I can't say that I have lots of free time, but I have some - what would be the top priority tasks at this point to push it all forward?

@SnareChops
Copy link

@SnareChops SnareChops commented Jul 8, 2018

@obiot So I think I'm going to need to bow out from this one. Some of the files are very easily converted, but others where the rule of single responsibility is broken is very difficult due to the design architecture of the application. To properly convert will be a much larger undertaking than you may have initially expected due to the organizational structure that the library was written in.

At this point I don't actually recommend converting the library to ES6, but instead create an ES6 wrapping layer over top of the ES5, then slowly convert file by file to ES6 as time goes on. Proper organization is critical for ES6 and following a strict rule of "Single Discreet Responsibility" within your files will make the transition much simpler.

I attempted to convert as much as I could and did convert every file in the project to ES6, but when trying to tie all of the imports together the problems really started to reveal themselves, and out of respect for you and your other contributors I decided not to start taking extreme measures completely reorganizing your project, though I feel thats what it really needs to make the transition properly.

By placing an ES6 wrapper over the ES5 code and reorganizing piece by piece, compiling with a babl / webpack pipeline should allow you to continue with releases while this process is going on, rather than having a branch getting stale during the conversion and then dealing with the metric ton of merge conflicts at the end attempting to pull in all of the updates from master.

If you should want or need it my fork has my completed work, but would advise against trying to use it due to the reasons that I stated above.

Best of luck with the project and I'm sorry that I wasn't able to achieve the goal, I just didn't want to cross any boundaries and disrespect you or your other contributors by reorganizing everything and making major changes to the entire project.

@scarejar
Copy link

@scarejar scarejar commented Jul 10, 2018

I'm for typescript also. It catches a lot of errors, is very non-intrusive to writing javascript, and it's self documenting as you write, along with auto-complete parameters and methods. I can't convey how much typescript makes javascript so much easier to work with into words but if the melonjs team still doesn't like typescript after testing it out, I stand behind the decision! tl;dr just make a fully informed decision

@obiot
Copy link
Member Author

@obiot obiot commented Jul 11, 2018

@SnareChops sorry for the late reply. Yes indeed the library conversion is a long task and imply rewriting/refactoring several major part of melonJS.... don't worry, I totally understand your point and definitely thank you for what you did try.

I'm interested though in your current work/progress, even though incomplete, It can help me progress by filling the gap with what I did so far (you can send a PR on the ES6-update branch, or send it by email to me at olivier.biot@me.com).

As for the ES6 Wrapper, it would definitely be nice to have, although I'm really wondering what is the added value at this stage, considering the current "Jay" inheritance model. And looking at my recent adventure with WeChat mini-program that requires ES6 (see here), it kind of gave me a feeling of the limit of such a wrapper (but maybe I'm wrong).

@obiot
Copy link
Member Author

@obiot obiot commented Jul 11, 2018

@scarejar I don't have anything against Typescript actually, just I never really used it (nor needed it), and to be honest everytime someone came up with the request and a proposal for a PR it never went through.

I agree though that TS allows to better highlight API discrepancies, and last time the topic came up, we modified/improved a few things (maybe it was with you, I do not remember).

Now if you are willing to help on this and up to task ...:P I'll be happy to start over, implement further changes in the current API, and probably try to use something like grunt-ts to automatically generate the TS files ?

@obiot obiot changed the title melonJS 7.0.0 : ES6 & others ES6 & others Jul 17, 2018
@SnareChops
Copy link

@SnareChops SnareChops commented Aug 23, 2018

@obiot If you want to get started into typescript you don't need to convert anything. Just rename the files from .js to .ts and run through the typescript compiler, that's all that is needed since any valid javascript is valid typescript. (Typescript is an extension of the base javascript language, not a different syntax like coffee script or anything like that)

Though if this is your first time I do recommend trying it out with a very small 2-3 file test project so that you can get your tsconfig.json file set the way you want and get that initial understanding of how the compiler works / exports files.

As for my work you should be able to pull it in yourself if you really want (https://github.com/SnareChops/melonJS/tree/ES6-update)

@kibertoad
Copy link
Contributor

@kibertoad kibertoad commented Aug 23, 2018

@obiot Please let me know if I could contribute to the merge somehow.

obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
as well convert the built-in default loader, and do not expose it anymore to the global me namespace
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
also fix a circular dependency between rendererable and container
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Aug 29, 2020
obiot added a commit that referenced this issue Sep 2, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
this is endless :)
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 3, 2020
obiot added a commit that referenced this issue Sep 4, 2020
obiot added a commit that referenced this issue Sep 4, 2020
obiot added a commit that referenced this issue Sep 4, 2020
obiot added a commit that referenced this issue Sep 4, 2020
obiot added a commit that referenced this issue Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants