+ All Categories
Home > Technology > Modular Design With EcmaScript 6 Queens JS Meetup

Modular Design With EcmaScript 6 Queens JS Meetup

Date post: 15-Feb-2017
Category:
Upload: daniel-ferrer
View: 874 times
Download: 1 times
Share this document with a friend
24
MODULAR DESIGN WITH ES6 @DANJFERRER QUEENS JS MEETUP / SEPTEMBER 2ND 2015
Transcript
Page 1: Modular Design With EcmaScript 6 Queens JS Meetup

MODULAR DESIGN WITH ES6@DANJFERRERQUEENS JS MEETUP / SEPTEMBER 2ND 2015

Page 2: Modular Design With EcmaScript 6 Queens JS Meetup

** Insert cheap plug/talk personal details here **

@danjferrer

[email protected]@gmail.com

Page 3: Modular Design With EcmaScript 6 Queens JS Meetup

- Modules: History and Current State In JS

- ES6 Syntax/Module Definitions

- Use with the browser today

- Why Modular Design + ES6 makes better code

Page 4: Modular Design With EcmaScript 6 Queens JS Meetup

WHAT IS MODULARITY?

Page 5: Modular Design With EcmaScript 6 Queens JS Meetup

“Separation of code into various pieces, maintaining separation of concerns, which in turn makes code easier to test and easier to refactor”

Page 6: Modular Design With EcmaScript 6 Queens JS Meetup

HOW ARE PIECES OF JAVASCRIPT CODE DEFINED TODAY?

-REQUIREJS DOCS

DEFINED VIA AN IMMEDIATELY EXECUTED FACTORY FUNCTION.

REFERENCES TO DEPENDENCIES ARE DONE VIA GLOBAL VARIABLE NAMES THAT WERE LOADED

VIA AN HTML SCRIPT TAG.

THE DEPENDENCIES ARE VERY WEAKLY STATED: THE DEVELOPER NEEDS TO KNOW THE RIGHT

DEPENDENCY ORDER. FOR INSTANCE, THE FILE CONTAINING BACKBONE CANNOT COME BEFORE

THE JQUERY TAG.

IT REQUIRES EXTRA TOOLING TO SUBSTITUTE A SET OF SCRIPT TAGS INTO ONE TAG FOR

OPTIMIZED DEPLOYMENT.

Page 7: Modular Design With EcmaScript 6 Queens JS Meetup

Do I need all my code in a single file?Do I need to write my code inside

many files?Do I need to write my code in various

modules?Can I handle a lot of script tags?

Should said tags be loaded in order?

Page 8: Modular Design With EcmaScript 6 Queens JS Meetup

REVEALING MODULES

Page 9: Modular Design With EcmaScript 6 Queens JS Meetup

I LITERALLY CAN’T EVEN

Page 10: Modular Design With EcmaScript 6 Queens JS Meetup

Let’s try to use less of these: <script>

Page 11: Modular Design With EcmaScript 6 Queens JS Meetup

JAVASCRIPT MODULE DEFINITIONSCommon JS Modules:

•Designed with compact syntax

•synchronous loading

•Primarily used for the server

•Used with NodeJS and Ringo

Asynchronous Module Definition (AMD)

•Syntax is slightly more complicated

•Asynchronous Loading

•Primarily used for the browser

•Fits better with JavaScripts async nature

Page 12: Modular Design With EcmaScript 6 Queens JS Meetup

COMMONJS VS AMD

Page 13: Modular Design With EcmaScript 6 Queens JS Meetup
Page 14: Modular Design With EcmaScript 6 Queens JS Meetup

MODULES IN ES 6/HARMONY

Page 15: Modular Design With EcmaScript 6 Queens JS Meetup

IMPORTS/EXPORTS

Page 16: Modular Design With EcmaScript 6 Queens JS Meetup

EXPORTING SINGLE FUNCTIONS

Page 17: Modular Design With EcmaScript 6 Queens JS Meetup

CLASSES ARE HERE!

Page 18: Modular Design With EcmaScript 6 Queens JS Meetup
Page 19: Modular Design With EcmaScript 6 Queens JS Meetup

USING AS YOUR COMPILER

Page 20: Modular Design With EcmaScript 6 Queens JS Meetup

$ NPM INSTALL -G BABEL$ BABEL-NODE

Page 21: Modular Design With EcmaScript 6 Queens JS Meetup

FOR CURRENT CJS AND AMD PROJECTS

Page 22: Modular Design With EcmaScript 6 Queens JS Meetup

SHOULD I/SHOULD I NOT?

Page 23: Modular Design With EcmaScript 6 Queens JS Meetup

•Declarative syntax and supports single/multiple imports/exportsSupports asynchronous loading out of the box

Programmatic APIStatic Module Structure

AND IT’S NATIVE

Page 24: Modular Design With EcmaScript 6 Queens JS Meetup

Recommended