PLOG - Modern Javascripting with Plone

17
"Modern" Javascript-ing Plone ... how to drink less while doing Javascript in Plone. / Rok Garbas @garbas

Transcript of PLOG - Modern Javascripting with Plone

Page 1: PLOG - Modern Javascripting with Plone

"Modern" Javascript-ingPlone

... how to drink less while doingJavascript in Plone.

/ Rok Garbas @garbas

Page 2: PLOG - Modern Javascripting with Plone

Products.ResourcesRegistry

orders resources,minimizes,

groups them.

Page 3: PLOG - Modern Javascripting with Plone

Nothing wrong with it,

right?

Hard to debug

Hard to keep resources up to date.

Nothing / Nada / Niente of our JS is tested.

Tricky for addons to plugin.

Page 4: PLOG - Modern Javascripting with Plone

Seriously...

We need to get out shittogether!

Page 5: PLOG - Modern Javascripting with Plone

PLOG pledgeOn my honor, I will try,

To serve Plone community and worship **all** Javascript

Gods,

To write Modular, Tested, Documented Javascript code

And to live by the Girl Scout Law.

Page 6: PLOG - Modern Javascripting with Plone

ModularJavascript

Page 7: PLOG - Modern Javascripting with Plone

AMD vs CommonJSScope

Remote/LocalAsynchrony

Page 8: PLOG - Modern Javascripting with Plone

AMD

CommonJS

// define wrapperdefine( // dependencies are specified in advance. ['modA', 'modB'], // the module is declared within a definition function. // dependencies are mapped into function parameters. function (modA, modB) { // inside here is the module's code. // the module is exported to the outside world via the // the definition function's returned value. var modC = modA + modB; return modC; });

// dependencies specified as neededvar modC = require('modC');

// the module is exported by decorating the `exports` free variable.exports.foo = require('modA') + require('modB');

Page 9: PLOG - Modern Javascripting with Plone

ResuireJSPaths for network/CDN resources.

Minimize resources.

Optimizing into one lite JavaScript file.

Page 10: PLOG - Modern Javascripting with Plone

Keepingresources up to

date

Page 11: PLOG - Modern Javascripting with Plone

JamManage dependencies

"npm" for browserReally nice integration with RequireJS

$ jam install backbone$ jam upgrade$ jam compile compiled.min.js$ jam compile --almond compiled-standalone.min.js

Page 12: PLOG - Modern Javascripting with Plone

TestingJavascript

Page 13: PLOG - Modern Javascripting with Plone

Test FrameworksQUnit

JasmineBusterMocha

Page 14: PLOG - Modern Javascripting with Plone

Test Assertionsexpect.js - Minimalistic BDD-style assertions for Node.JS

and the class="fragment"browser.should.js - BDD style assertions for node.js

better-assert - c-style assert() for nodejs, reporting theexpression string as the error message

Buster, Jasmine -

Page 15: PLOG - Modern Javascripting with Plone

My assertion library choiceChai is a BDD / TDD assertion library for node and the

browser.chai.should();

foo.should.be.a('string');

foo.should.equal('bar');

foo.should.have.length(3);

tea.should.have.property('flavors').with.length(3);

var expect = chai.expect;

expect(foo).to.be.a('string');

expect(foo).to.equal('bar');

expect(foo).to.have.length(3);

expect(tea).to.have.property('flavors').with.length(3);

var assert = chai.assert;

assert.typeOf(foo, 'string');

assert.equal(foo, 'bar');

assert.lengthOf(foo, 3)

assert.property(tea, 'favors');

assert.lengthOf(tea.flavors, 3);

Page 16: PLOG - Modern Javascripting with Plone

Test runnersQUnit, Jasmine, Buster, Mocha

TEST'EM

Page 17: PLOG - Modern Javascripting with Plone

Mockupproject