ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
YUIConf2012: Mojito for YUI Developers
Caridy Patino
Bartender at Yahoo! Mojito Team
Principal Engineer at Yahoo! Search

caridy@yahoo-inc.com
@caridy
for YUI developer
Agenda:

- YUI Apps overview
- Mojito for YUI Apps
- Mojito components
- Mojito Mojits
- Execution context & con?gurations
- DEMO
- Extending Mojito
There are three things we do when creating
             YUI applications:
The Seed ?le(s)
YUIConf2012: Mojito for YUI Developers
Example of a composite seed from search.yahoo.com:

http://a.l.yimg.com/pv/lib/s9/srp-core-js-1_201106101018.js
http://a.l.yimg.com/pv/lib/s9/srp-core-js-2_201210020629.js
The YUI().use() statement
YUIConf2012: Mojito for YUI Developers
The YUI con?g
YUI_config = {filter: ¡°debug¡±};
YUI.GlobalConfig = {filter: ¡°debug¡±};
YUI.applyConfig({filter: ¡°debug¡±});
Y.applyConfig({filter: ¡°debug¡±});
YUI({filter: ¡°debug¡±});
... and there is a four thing we also do:
The YUI.add() magic to create new building blocks
          or to bundle business logic
YUIConf2012: Mojito for YUI Developers
... and here is where things get messy
How to organize our ?les?
How to con?gure our app to use our ?les?
How to build those ?les for production?
       How to optimize them?
       How to push to CDN?
... and this list goes on and on!
We are on our own on this!
YUI Runtimes
There are four different kind of applications
        that we can build with YUI
Traditional Web Pages
HTML5 Web App (a la YAF)
Of?ine HTML5 Hybrid App (a la phonegap)
NodeJS App to serve traf?c
Nowadays, when we build a product, we usually
  need to build more that one type of app
We can group the runtimes by
     Server and Client
YUI 4x4

         Seeds   YUI use   YUI con?g   YUI add

 Web      x         x         x          x

 YAF      x         x         x          x

Hybrid    x         x         x          x

NodeJS              x         x          x
Mojito for YUI Developer




$ npm install mojito -g
YUI vs Mojito
YUI and Mojito
YUI is a library of building blocks
to create javascript applications!
Mojito is a boilerplate framework for
       javascript applications!
Mojito is a boilerplate framework for
     javascript YUI applications...
... and YUI modules are the building blocks
              for those apps
Mojito does NOT provide any building block,
      it provides archetypes and utilities
Mojito Architecture Components
Mojito Components

          mojito-cli


                  mojito-store


mojito-server

                  mojito-core



        mojito-client
Command line interface
$ mojito <something>
            mojito-cli


                    mojito-store


  mojito-server

                    mojito-core



          mojito-client
The Store is an abstraction layer for a
    mojito application ?lesystem

                 mojito-cli


                         mojito-store


       mojito-server

                         mojito-core



               mojito-client
Mojito core is the dispatch engine
and a runtime abstraction for logical pieces

                    mojito-cli


                            mojito-store


          mojito-server

                            mojito-core



                  mojito-client
Mojito server for NodeJS
      (a la express)

           mojito-cli


                   mojito-store


 mojito-server

                   mojito-core



         mojito-client
Mojito client
       (a la YAF)

          mojito-cli


                  mojito-store


mojito-server

                  mojito-core



        mojito-client
mojito-cli



 The capabilities of                     mojito-store

each component can
be augmented easily    mojito-server

                                         mojito-core



                               mojito-client
mojito-cli


                                          mojito-store
Each component can
 be used in isolation   mojito-server

                                          mojito-core



                                mojito-client
Server runtime work?ow

 analyze req       route      ?ush static or error
(middleware)       exists?


                             dispatch

                  dispatch
                                            deploy    no   ?ush content
                                            client?


                                                yes
                                        generate seed
                                                            ?ush html
                                          and Y.use
Client runtime work?ow

                  route
                            navigate
analyze url       exists?


                       dispatch

                                         valid
                                                  yes
                 dispatch              runtime?           execute

                                            no

                                    delegate to
                                                        ?ush content
                                  remote runtime
Growing your software with Mojito
Applications will tent to grow organically
by adding complexity and new logical pieces
YUIConf2012: Mojito for YUI Developers
Some of these logical pieces can be reuse
across different form factors and devices
In Mojito, a logical piece is called a Mojit
and Applications are just composition of Mojits
YUIConf2012: Mojito for YUI Developers
In Mojito, the simplest app
    contains one Mojit




$   mojito create app demo
$   cd ./demo
$   mojito create mojit foo
$   mojito start
Mojits in Mojito
A Mojit should be:

- sharable
- con?gurable
- customizable
- nest-able
- mutable
Mojit structure
A Mojit is a composition of entities in a
form of JS, CSS, templates, con?gurations,
             and other assets
$ mojito create mojit foo
Entity Registration in Mojito
In Mojito, there are three different
      registration processes
By YUI.add(), which is applicable for
 yui modules and it is used by YUI
By af?nity, which is applicable for
javascript ?les, and it is used by mojito-store
The af?nity could be:
server, client or common
The af?nity registration solves two use cases:


   Bar
            requires
 (server)
                          Foo
                       (common)
   Baz
 (client)   requires
                                               Bar
                                             (server)

                          Foo
                                  requires
                       (common)
                                               Bar
                                             (client)
By selector, which is applicable for js, css and templates,
     and it is used by mojito-store during run time
The selector could be <anything> in a form of a string
The selector registration solves one use case:


                                             pick ¡°bar.iphone¡±      Bar
                                                                 (iphone)


 Foo
       require ¡°bar¡±                                                Bar
                              mojito-store
                                                                  (ipad)
                              selector
                       iphone,mobile,*

                                                                   Bar
                                  context                        (mobile)
render(data, {
    view: {
        name: ¡°bar¡±
    }
});
YUI 4x4

         Seeds   YUI use   YUI con?g   YUI add

 Web                x                    x

 YAF                x                    x

Hybrid              x                    x

NodeJS              x                    x
Mojito execution context and con?gurations
Mojito uses the Yahoo! Con?guration Bundle
                 (aka YCB)




       http://github.com/yahoo/ycb
Mojito Server and Client abstractions will
take care of resolving execution context
    and con?gurations when needed
path/to/demo/application.json
path/to/mojits/foo/de?nition.json
Accessing con?guration from Mojit¡¯s controller
Mojito does heavy use of con?gurations
        in a form of JSON ?les
Customizing Seed ?les
Customizing Seed ?les
YUI 4x4

         Seeds   YUI use   YUI con?g   YUI add

 Web      x                   x

 YAF      x                   x

Hybrid    x                   x

NodeJS                        x
DEMO
Extending Mojito
Mojito embraces NPM to enable
     software composition
package.json
$ cd path/to/app/
$ npm install mojit-trending-now
... and from the application point of view
there is not distinction because the mojito-store
              will ?atten the structure
Mojito embraces NPM to support
boilerplate extensions and addons
$ cd path/to/app/
$ npm install mojito-sass
$ npm install mojito-shaker
Mojito extensions can be:

- mojito cli commands
- store addons
- mojits, archetypes & renderers
- middleware
- action-context addons
... and we need your help to build those
              extensions!
Mojito Today
// Mojito 101

$   npm install mojito@0.5.0pr4 -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
// Mojito 101 (second part)

$   mojito   build html5app ./
$   mojito   gv client
$   mojito   jslint app ./
$   mojito   docs app ./
$   mojito   info ./
$   mojito   help
Current versions:
- mojito@0.5.0pr4
- yui@3.7.3
Mojito Tomorrow
- YAF integration is coming
- Performance is paramount
- Mojito extensions:
  (debugger, pro?ler, less, sass,
   coffeescript, typescript, etc)
One last thing...
http://github.com/yahoo/mojito
All the code from the presentation
             is available here:


http://gist.github.com/4070536
Thank you!
   @caridy

More Related Content

YUIConf2012: Mojito for YUI Developers