Download - YUIConf2012: Mojito for YUI Developers

Transcript
Page 1: YUIConf2012: Mojito for YUI Developers
Page 2: YUIConf2012: Mojito for YUI Developers

Caridy PatinoBartender at Yahoo! Mojito TeamPrincipal Engineer at Yahoo! Search

[email protected]@caridy

Page 3: YUIConf2012: Mojito for YUI Developers

for YUI developer

Page 4: YUIConf2012: Mojito for YUI Developers

Agenda:

- YUI Apps overview- Mojito for YUI Apps- Mojito components- Mojito Mojits- Execution context & configurations- DEMO- Extending Mojito

Page 5: YUIConf2012: Mojito for YUI Developers

There are three things we do when creating YUI applications:

Page 6: YUIConf2012: Mojito for YUI Developers

The Seed file(s)

Page 7: YUIConf2012: Mojito for YUI Developers
Page 8: YUIConf2012: Mojito for YUI Developers

http://a.l.yimg.com/pv/lib/s9/srp-core-js-1_201106101018.jshttp://a.l.yimg.com/pv/lib/s9/srp-core-js-2_201210020629.js

Example of a composite seed from search.yahoo.com:

Page 9: YUIConf2012: Mojito for YUI Developers

The YUI().use() statement

Page 10: YUIConf2012: Mojito for YUI Developers
Page 11: YUIConf2012: Mojito for YUI Developers

The YUI config

Page 12: YUIConf2012: Mojito for YUI Developers

YUI_config = {filter: “debug”};YUI.GlobalConfig = {filter: “debug”};YUI.applyConfig({filter: “debug”});Y.applyConfig({filter: “debug”});YUI({filter: “debug”});

Page 13: YUIConf2012: Mojito for YUI Developers

... and there is a four thing we also do:

Page 14: YUIConf2012: Mojito for YUI Developers

The YUI.add() magic to create new building blocksor to bundle business logic

Page 15: YUIConf2012: Mojito for YUI Developers
Page 16: YUIConf2012: Mojito for YUI Developers

... and here is where things get messy

Page 17: YUIConf2012: Mojito for YUI Developers

How to organize our files?

Page 18: YUIConf2012: Mojito for YUI Developers

How to configure our app to use our files?

Page 19: YUIConf2012: Mojito for YUI Developers

How to build those files for production?How to optimize them?How to push to CDN?

Page 20: YUIConf2012: Mojito for YUI Developers

... and this list goes on and on!

Page 21: YUIConf2012: Mojito for YUI Developers

We are on our own on this!

Page 22: YUIConf2012: Mojito for YUI Developers

YUI Runtimes

Page 23: YUIConf2012: Mojito for YUI Developers

There are four different kind of applicationsthat we can build with YUI

Page 24: YUIConf2012: Mojito for YUI Developers

Traditional Web Pages

Page 25: YUIConf2012: Mojito for YUI Developers

HTML5 Web App (a la YAF)

Page 26: YUIConf2012: Mojito for YUI Developers

Offline HTML5 Hybrid App (a la phonegap)

Page 27: YUIConf2012: Mojito for YUI Developers

NodeJS App to serve traffic

Page 28: YUIConf2012: Mojito for YUI Developers

Nowadays, when we build a product, we usuallyneed to build more that one type of app

Page 29: YUIConf2012: Mojito for YUI Developers

We can group the runtimes byServer and Client

Page 30: YUIConf2012: Mojito for YUI Developers

YUI 4x4

Seeds YUI use YUI config YUI add

Web x x x x

YAF x x x x

Hybrid x x x x

NodeJS x x x

Page 31: YUIConf2012: Mojito for YUI Developers

Mojito for YUI Developer

$ npm install mojito -g

Page 32: YUIConf2012: Mojito for YUI Developers

YUI vs Mojito

Page 33: YUIConf2012: Mojito for YUI Developers

YUI and Mojito

Page 34: YUIConf2012: Mojito for YUI Developers

YUI is a library of building blocksto create javascript applications!

Page 35: YUIConf2012: Mojito for YUI Developers

Mojito is a boilerplate framework forjavascript applications!

Page 36: YUIConf2012: Mojito for YUI Developers

Mojito is a boilerplate framework forjavascript YUI applications...

Page 37: YUIConf2012: Mojito for YUI Developers

... and YUI modules are the building blocksfor those apps

Page 38: YUIConf2012: Mojito for YUI Developers

Mojito does NOT provide any building block,it provides archetypes and utilities

Page 39: YUIConf2012: Mojito for YUI Developers

Mojito Architecture Components

Page 40: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

Mojito Components

mojito-client

Page 41: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

Command line interface$ mojito <something>

mojito-client

Page 42: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

The Store is an abstraction layer for amojito application filesystem

mojito-client

Page 43: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

Mojito core is the dispatch engineand a runtime abstraction for logical pieces

mojito-client

Page 44: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

Mojito server for NodeJS(a la express)

mojito-client

Page 45: YUIConf2012: Mojito for YUI Developers

mojito-store

mojito-cli

mojito-server

mojito-core

Mojito client(a la YAF)

mojito-client

Page 46: YUIConf2012: Mojito for YUI Developers

The capabilities of each component canbe augmented easily

mojito-store

mojito-cli

mojito-server

mojito-core

mojito-client

Page 47: YUIConf2012: Mojito for YUI Developers

Each component can be used in isolation

mojito-store

mojito-cli

mojito-server

mojito-core

mojito-client

Page 48: YUIConf2012: Mojito for YUI Developers

Server runtime workflow

routeexists?

flush static or error

dispatch

analyze req(middleware)

dispatch deployclient?

noflush content

generate seedand Y.use

yes

flush html

Page 49: YUIConf2012: Mojito for YUI Developers

Client runtime workflow

routeexists?

navigate

dispatch

analyze url

dispatch valid runtime?

yesexecute

delegate to remote runtime

no

flush content

Page 50: YUIConf2012: Mojito for YUI Developers

Growing your software with Mojito

Page 51: YUIConf2012: Mojito for YUI Developers

Applications will tent to grow organically by adding complexity and new logical pieces

Page 52: YUIConf2012: Mojito for YUI Developers
Page 53: YUIConf2012: Mojito for YUI Developers

Some of these logical pieces can be reuseacross different form factors and devices

Page 54: YUIConf2012: Mojito for YUI Developers

In Mojito, a logical piece is called a Mojitand Applications are just composition of Mojits

Page 55: YUIConf2012: Mojito for YUI Developers
Page 56: YUIConf2012: Mojito for YUI Developers

In Mojito, the simplest appcontains one Mojit

$ mojito create app demo$ cd ./demo$ mojito create mojit foo$ mojito start

Page 57: YUIConf2012: Mojito for YUI Developers

Mojits in Mojito

Page 58: YUIConf2012: Mojito for YUI Developers

A Mojit should be:

- sharable- configurable- customizable- nest-able- mutable

Page 59: YUIConf2012: Mojito for YUI Developers

Mojit structure

Page 60: YUIConf2012: Mojito for YUI Developers

A Mojit is a composition of entities in aform of JS, CSS, templates, configurations,

and other assets

Page 61: YUIConf2012: Mojito for YUI Developers

$ mojito create mojit foo

Page 62: YUIConf2012: Mojito for YUI Developers

Entity Registration in Mojito

Page 63: YUIConf2012: Mojito for YUI Developers

In Mojito, there are three differentregistration processes

Page 64: YUIConf2012: Mojito for YUI Developers

By YUI.add(), which is applicable foryui modules and it is used by YUI

Page 65: YUIConf2012: Mojito for YUI Developers

By affinity, which is applicable forjavascript files, and it is used by mojito-store

Page 66: YUIConf2012: Mojito for YUI Developers

The affinity could be:server, client or common

Page 67: YUIConf2012: Mojito for YUI Developers

The affinity registration solves two use cases:

Foo(common)

Bar(server)

Baz(client) requires

requires

Foo(common)

Bar(server)

Bar(client)

requires

Page 68: YUIConf2012: Mojito for YUI Developers

By selector, which is applicable for js, css and templates,and it is used by mojito-store during run time

Page 69: YUIConf2012: Mojito for YUI Developers

The selector could be <anything> in a form of a string

Page 70: YUIConf2012: Mojito for YUI Developers

The selector registration solves one use case:

Foo

Bar(iphone)

Bar(mobile)

require “bar”mojito-store

context

selector iphone,mobile,*

Bar(ipad)

pick “bar.iphone”

Page 71: YUIConf2012: Mojito for YUI Developers

render(data, { view: { name: “bar” }});

Page 72: YUIConf2012: Mojito for YUI Developers

YUI 4x4

Seeds YUI use YUI config YUI add

Web x x

YAF x x

Hybrid x x

NodeJS x x

Page 73: YUIConf2012: Mojito for YUI Developers

Mojito execution context and configurations

Page 74: YUIConf2012: Mojito for YUI Developers

Mojito uses the Yahoo! Configuration Bundle(aka YCB)

http://github.com/yahoo/ycb

Page 75: YUIConf2012: Mojito for YUI Developers

Mojito Server and Client abstractions willtake care of resolving execution context

and configurations when needed

Page 76: YUIConf2012: Mojito for YUI Developers

path/to/demo/application.json

Page 77: YUIConf2012: Mojito for YUI Developers

path/to/mojits/foo/definition.json

Page 78: YUIConf2012: Mojito for YUI Developers

Accessing configuration from Mojit’s controller

Page 79: YUIConf2012: Mojito for YUI Developers

Mojito does heavy use of configurationsin a form of JSON files

Page 80: YUIConf2012: Mojito for YUI Developers

Customizing Seed files

Page 81: YUIConf2012: Mojito for YUI Developers

Customizing Seed files

Page 82: YUIConf2012: Mojito for YUI Developers

YUI 4x4

Seeds YUI use YUI config YUI add

Web x x

YAF x x

Hybrid x x

NodeJS x

Page 83: YUIConf2012: Mojito for YUI Developers

DEMO

Page 84: YUIConf2012: Mojito for YUI Developers

Extending Mojito

Page 85: YUIConf2012: Mojito for YUI Developers

Mojito embraces NPM to enablesoftware composition

Page 86: YUIConf2012: Mojito for YUI Developers

package.json

Page 87: YUIConf2012: Mojito for YUI Developers

$ cd path/to/app/$ npm install mojit-trending-now

Page 88: YUIConf2012: Mojito for YUI Developers

... and from the application point of viewthere is not distinction because the mojito-store

will flatten the structure

Page 89: YUIConf2012: Mojito for YUI Developers

Mojito embraces NPM to supportboilerplate extensions and addons

Page 90: YUIConf2012: Mojito for YUI Developers

$ cd path/to/app/$ npm install mojito-sass$ npm install mojito-shaker

Page 91: YUIConf2012: Mojito for YUI Developers

Mojito extensions can be:

- mojito cli commands- store addons- mojits, archetypes & renderers- middleware- action-context addons

Page 92: YUIConf2012: Mojito for YUI Developers

... and we need your help to build thoseextensions!

Page 93: YUIConf2012: Mojito for YUI Developers

Mojito Today

Page 94: YUIConf2012: Mojito for YUI Developers

// Mojito 101

$ npm install [email protected] -g$ mojito version$ mojito create app demo$ cd ./demo$ mojito create mojit foo$ mojito jslint app . -p$ mojito test app . --coverage$ mojito start --context ”environment:dev”$ curl http://localhost:8666/@foo/index

Page 95: YUIConf2012: Mojito for YUI Developers

// Mojito 101 (second part)

$ mojito build html5app ./$ mojito gv client$ mojito jslint app ./$ mojito docs app ./$ mojito info ./$ mojito help

Page 97: YUIConf2012: Mojito for YUI Developers

Mojito Tomorrow

Page 98: YUIConf2012: Mojito for YUI Developers

- YAF integration is coming- Performance is paramount- Mojito extensions: (debugger, profiler, less, sass, coffeescript, typescript, etc)

Page 99: YUIConf2012: Mojito for YUI Developers

One last thing...

Page 100: YUIConf2012: Mojito for YUI Developers

http://github.com/yahoo/mojito

Page 101: YUIConf2012: Mojito for YUI Developers

http://gist.github.com/4070536

All the code from the presentationis available here:

Page 102: YUIConf2012: Mojito for YUI Developers

Thank you! @caridy