Why, What and Where Moodle’s AMD

Moodle is it still alive? Yes, and step-by-step it became more contemporary. I appreciate new features, which helps makes our life more easy, and yes, you’r right I talk about AMD.

Asynchronous module definition (AMD) deserve popularity by getting to us power to separate out code into small useful pieces and solve an issue with dependency injection (I remember that “good” times when we include all into footer.php, but now we can relax and drink martini).

But it still is JavaScript, I mean there is no OOP and strong recommendations how to write code inside our modules. It’s like a “black box”, you get in dependencies, then push out object with public methods, which can be accessible even from PHP.

Access via PHP looks strange (Oh my God!… Why don’t trust to client’s browser?), but it brings to us more good security level and new benefits, because it’s still hard to check which role user has on front-end side.

Moodle Using NodeJS grunt

It was interesting to me, because I love NodeJS and know what this technology can do. Grunt is little bit old, but good solution for production build. And there is eslint too, so we can install all dependencies and run grunt to pass all tests for out AMD JS code and then uglify it:

// on your Moodle root
npm install
grunt amd

What is Great to Read Before Learn AMD?

First at all you need to understand what JavaScript it isn’t an OOP language. I found this post and it was awesome to reed it, because I seen what most of back-end developer’s doesn’t understand what JS Prototypes are and how to cook them.

Also you can read about JavaScript Modules because there is two most popular ways to organize a code inside Moodle AMD: JS Module or JS Class. That’s why I put links for that two articles.

You can read more about Moodle AMD in an official docs, I was try to put some good background before you start to do that. Thanks for reading, will try to post more interesting things soon.

Show your support

Clapping shows how much you appreciated Alexandr Berezhnyk’s story.