Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'develop-perf' of git://github.com/yahoo/mojito into par…
…tials
  • Loading branch information
caridy committed Nov 21, 2012
2 parents e6499c5 + bba2079 commit 9d75095
Show file tree
Hide file tree
Showing 220 changed files with 457 additions and 5,987 deletions.
4 changes: 0 additions & 4 deletions docs/dev_guide/code_exs/adding_assets.rst
Expand Up @@ -2,10 +2,6 @@
Adding CSS
==========

.. raw:: html

<span class="testimate">Time Estimate: 10 minutes</span>&nbsp;&nbsp;&nbsp;<span class="difficulty">Difficulty: Beginner</span>

**Time Estimate:** 10 minutes

**Difficulty:** Beginner
Expand Down
42 changes: 21 additions & 21 deletions docs/dev_guide/code_exs/view_engines.rst
Expand Up @@ -54,14 +54,14 @@ Installing a Rendering Engine
You could write your own rendering engine or copy code into your Mojito
application, but this example follows the most common use case of installing
a rendering engine with ``npm``. We will be installing the rendering engine
`EJS <http://embeddedjs.com/>`_ with ``npm``.
`EJS <http://embeddedjs.com/>`_ with ``npm``.

Because your Mojito application is simply a ``npm`` module, you can have a
``node_modules`` directory for locally installing other modules. Thus, from
your application directory, you would use the following ``npm`` command to
install ``ejs``:

``{app_dir}/ $ npm install ejs``
``$ npm install ejs``

After you have installed ``ejs``, a ``node_modules`` directory will be created
with the contents similar to the following:
Expand Down Expand Up @@ -114,45 +114,45 @@ The view engine addon must have the following:
view engine addon with the name ``addons-viewengine-ejs`` in our code example
as seen below.

.. code-block:: javascript
.. code-block:: javascript
YUI.add('addons-viewengine-ejs', function(Y, NAME) {
YUI.add('addons-viewengine-ejs', function(Y, NAME) {
// The addon name 'addons-viewengine-hb' is registered by YUI.add
// The addon name 'addons-viewengine-hb' is registered by YUI.add
}, '0.1.0', {requires: []});
}, '0.1.0', {requires: []});
- a prototype of the object has the following two methods ``render`` and
``compiler`` as shown below. We will look at the ``render`` and ``compile``
methods more closely in the next section.

.. code-block:: javascript
.. code-block:: javascript
...
...
EjsAdapter.prototype = {
EjsAdapter.prototype = {
render: function(data, mojitType, tmpl, adapter, meta, more) {
...
},
compiler: function(tmpl) {
...
render: function(data, mojitType, tmpl, adapter, meta, more) {
...
},
compiler: function(tmpl) {
...
}
...
- an object that is assigned to ``Y.mojito.addons.viewEngines.{view_engine_name}``.
In our example, the constructor ``EjsAdapter`` is assigned to the namespace
``Y.namespace('mojito.addons.viewEngines').ejs`` or ``Y.mojito.addons.viewEngines.ejs``.
.. code-block:: javascript
.. code-block:: javascript
...
...
function EjsAdapter(viewId) {
this.viewId = viewId;
}
...
Y.namespace('mojito.addons.viewEngines').ejs = EjsAdapter;
function EjsAdapter(viewId) {
this.viewId = viewId;
}
...
Y.namespace('mojito.addons.viewEngines').ejs = EjsAdapter;
.. _ve_addon_create-render_compile:
Expand Down
34 changes: 10 additions & 24 deletions docs/dev_guide/intro/mojito_configuring.rst
Expand Up @@ -434,16 +434,9 @@ Some of the properties of the ``config`` object used for configuring logging are
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| Property | Data Type | Default Value | Description |
+======================+===============+===================+===========================================================+
| ``buffer`` | boolean | false | Determines whether Mojito should buffer log |
| | | | entries (``true``) or output each as they occur |
| | | | (``false``). |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| ``debug`` | boolean | true | Determines whether ``Y.log`` messages are written to the |
| | | | browser console. |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| ``defaultLevel`` | string | "info" | Specifies the default log level to log entries. See |
| | | | `Log Levels <../topics/mojito_logging.html#log-levels>`_. |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| ``logExclude`` | object | none | Excludes the logging of the YUI module(s) specified. |
| | | | For example: ``logExclude: { "logModel": true }`` |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
Expand All @@ -454,13 +447,7 @@ Some of the properties of the ``config`` object used for configuring logging are
| | | | log output. See |
| | | | `Log Levels <../topics/mojito_logging.html#log-levels>`_. |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| ``maxBufferSize`` | number | 1024 | If ``buffer`` is set to ``true``, specifies the |
| | | | number of log entries to store before flushing to |
| | | | output. |
+----------------------+---------------+-------------------+-----------------------------------------------------------+
| ``timestamp`` | boolean | true | Determines whether the timestamp is included in |
| | | | the log output. |
+----------------------+---------------+-------------------+-----------------------------------------------------------+




Expand Down Expand Up @@ -1182,7 +1169,7 @@ the action are specified in the ``"foo_default"`` object.
"call": "foo-1.index"
}
In this code snippet from ``controller.js``, the `Url addon <../../api/classes/Url.common.html>`_
In this code snippet from ``controller.js``, the `Url addon <../../api/classes/Url.common.html>`_
with the ``make`` method use the mojit instance and function specified in the
``routes.json`` above to create the URL ``/foo`` with the query string parameters
``?foo=bar``.
Expand All @@ -1202,9 +1189,9 @@ The ``index`` function above returns the following URL: ``http://localhost:8666/
Accessing Configurations from Mojits
====================================

The controller, model, and binder can access mojit configurations from the ``init``
The model, and binder can access mojit configurations from the ``init``
function. The controller and model are passed ``configuration`` objects. The controller
can also access configuration from other functions through the ``actionContext`` object.
can access configuration the ``actionContext`` object and the ``Config`` addon.
The ``init`` function in the binder instead of a configuration object is passed the
``mojitProxy`` object, which enables you to get the configurations.

Expand Down Expand Up @@ -1310,9 +1297,8 @@ configurations of ``application.json`` override those in ``defaults.json``.
Controller
##########

In the controller, the mojit-level configurations are passed to the ``init`` function. In
other controller functions, you can access mojit-level configurations from the
``actionContext`` object using the `Config addon <../../api/classes/Config.common.html>`_.
Controllers can access mojit-level configurations from the ``actionContext`` object
using the `Config addon <../../api/classes/Config.common.html>`_.
Use ``ac.config.get`` to access configuration values from ``application.json`` and
``defaults.json`` and ``ac.config.getDefinition`` to access definition values from
``definition.json``.
Expand All @@ -1323,10 +1309,10 @@ Use ``ac.config.get`` to access configuration values from ``application.json`` a
Model
#####

The ``init`` function in the model is also passed the mojit-level configurations. If other
model functions need the configurations, you need to save the configurations to the
``this`` reference because no ``actionContext`` object is passed to the model, so your
model does not have access to the ``Config`` addon.
The ``init`` function in the model is also passed the mojit-level configurations.
If other model functions need the configurations, you need to save the
configurations to the ``this`` reference because no ``actionContext`` object is
passed to the model, so your model does not have access to the ``Config`` addon.


.. _access_mojit-binder:
Expand Down
3 changes: 2 additions & 1 deletion docs/dev_guide/intro/mojito_mojits.rst
Expand Up @@ -13,7 +13,7 @@ implementation details, see the following:

- `Mojit Configuration <mojito_configuring.html#mojit-configuration>`_
- `Mojits <mojito_apps.html#mojits>`_ in the `Mojito Applications <mojito_apps.html>`_
chapter
chapter
- `MVC in Mojito <mojito_mvc.html>`_
- `Mojito API Documentation <../../api>`_

Expand Down Expand Up @@ -176,6 +176,7 @@ and has the following characteristics:
- versioned and immutable for a given version.

Metadata can be packaged as a unit (e.g., as a zip file) for:

- configuration schema
- data requirements
- mojit dependencies
Expand Down
8 changes: 5 additions & 3 deletions docs/dev_guide/intro/mojito_mvc.rst
Expand Up @@ -420,7 +420,7 @@ For example, if you wanted to use the ``photo_search`` function in the model for
``flickr`` mojit, you would use the following: ``ac.models.get('flickr').photo_search(args, callback);``
The ``controller.server.js`` below shows a simple example of calling
``get_data`` from the model of the ``simple`` mojit.
``get_data`` from the model ``simpleModel``.
.. code-block:: javascript
Expand Down Expand Up @@ -455,8 +455,10 @@ The controller also uses the ActionContext object to send data to the view.
Calling the ``done`` method from the ActionContext object, you can send literal
strings or objects, with the latter being interpolated in template tags that are
rendered by the appropriate view engine. The ``done`` method should only be
called once. If neither ``done`` nor ``error`` is called, your application will
hang waiting for output.
called once. If neither ``done`` nor ``error`` is called within 60 seconds, Mojito
will log a warning and invoke ``error`` with a Timeout error.
You can change the default timeout value of 60000ms (60 seconds) by setting the
``actionTimeout`` property of your application configuration.
In the example ``controller.server.js`` below, the ``index`` function sends the ``user``
object to the ``index`` template.
Expand Down
4 changes: 1 addition & 3 deletions docs/dev_guide/intro/mojito_static_resources.rst
Expand Up @@ -11,9 +11,7 @@ URL that contains the following three components:
application, or the mojit depending on the level of the resource.
- **relative path** - the path relative to the source path.

The URL of the static URL has the following syntax:

``/static/{source_path}/{relative_path}``
The URL of the static URL has the following syntax: ``/static/{source_path}/{relative_path}``

.. _static_resources-prefix:

Expand Down
38 changes: 19 additions & 19 deletions docs/dev_guide/topics/mojito_extensions.rst
Expand Up @@ -461,7 +461,7 @@ Mojito framework and the rendering engine.

In the following sections, we will be discussing how to create a view engine
addon that relies on a rendering engine, not how to write code that renders
templates.
templates.

.. _ve_overview-term:

Expand Down Expand Up @@ -571,42 +571,42 @@ The view engine addon must have the following:

- a ``YUI.add`` statement to register the addon. For example:

.. code-block:: javascript
.. code-block:: javascript
YUI.add('addons-viewengine-hb', function(Y, NAME) {
YUI.add('addons-viewengine-hb', function(Y, NAME) {
// The addon name 'addons-viewengine-hb' is registered by YUI.add
// The addon name 'addons-viewengine-hb' is registered by YUI.add
}, '0.1.0', {requires: []});
}, '0.1.0', {requires: []});
- an object that is assigned to ``Y.mojito.addons.viewEngines.{view_engine_name}``
as seen below:

.. code-block:: javascript
.. code-block:: javascript
...
...
function EjsAdapter(viewId) {
this.viewId = viewId;
}
...
Y.namespace('mojito.addons.viewEngines').ejs = EjsAdapter;
function EjsAdapter(viewId) {
this.viewId = viewId;
}
...
Y.namespace('mojito.addons.viewEngines').ejs = EjsAdapter;
- a prototype of the object has the following two methods ``render`` and ``compiler``
as shown below:

.. code-block:: javascript
.. code-block:: javascript
...
...
EjsAdapter.prototype = {
EjsAdapter.prototype = {
render: function(data, mojitType, tmpl, adapter, meta, more) {
render: function(data, mojitType, tmpl, adapter, meta, more) {
...
},
compiler: function(tmpl) {
},
compiler: function(tmpl) {
...
}
}
...
Expand Down
66 changes: 0 additions & 66 deletions docs/dev_guide/topics/mojito_logging.rst
Expand Up @@ -36,12 +36,6 @@ Log Defaults
The server and client log settings have the following default values:

- ``logLevel:`` ``DEBUG`` - log level filter.
- ``yui:`` ``true`` - determines whether YUI library logs are displayed.
- ``buffer:`` ``false`` - determines whether logs are buffered.
- ``maxBufferSize: 1024`` - the number of logs the buffer holds before auto-flushing.
- ``timestamp: true`` - log statements are given a timestamp if value is true.
- ``defaultLevel: 'info'`` - if ``Y.log`` is called without a log level, this is the
default.

.. _mojito_logging-config:

Expand All @@ -61,7 +55,6 @@ overrides the defaults for ``logLevel`` and ``buffer``.
"yui": {
"config": {
"level": "error",
"buffer": true
}
},
...
Expand Down Expand Up @@ -91,66 +84,7 @@ context with the log configuration shown below:
}
]
.. _mojito_logging-buffering:
Log Buffering
=============

To avoid performance issues caused by logging, you can enable buffering, which will
configure Mojito to cache all logs in memory. You can force Mojito to flush the logs with
the ``Y.log`` function or setting the maximum buffer size. The following sections show you
how to enable buffering and force Mojito to flush the cached logs.

.. _logging_buffering-enable:

Enable Buffering
----------------

To configure Mojito to buffer your logs, set the ``buffer`` property to ``true`` in the
``yui.config`` object as shown in the example ``application.json`` below.

.. code-block:: javascript
[
{
"settings": [ "master" ],
"yui": {
"config": {
"buffer": true
}
},
...
}
]
.. _logging_buffering-flush:

Flush Cached Logs
-----------------

Mojito provides you with two ways to forcefully flush cached logs. When you have buffering
enabled, you can force Mojito to flush the cached logs with ``Y.log(({flush: true})``.
You can also set the maximum buffer size, so that Mojito will flush cached logs after the
cache has reached the maximum buffer size.

In the example ``application.json`` below, the maximum buffer size is set to be 4096 bytes.
Once the log cache reaches this size, the logs are then flushed. The default size of the
log cache is 1024 bytes.

.. code-block:: javascript
[
{
"settings": [ "master" ],
"yui": {
"config": {
"buffer": true,
"maxBufferSize": 4096
}
},
...
}
]
.. _mojito_logging-custom:

Expand Down
2 changes: 1 addition & 1 deletion docs/dev_guide/topics/mojito_run_dyn_defined_mojits.rst
Expand Up @@ -376,7 +376,7 @@ Adapter Functions
The functions ``ac.done``, ``ac.flush``, and ``ac.error`` defined in the ``adapter``
object are actually implemented by the Mojito framework. For example, before
``adapter.done`` is executed, Mojito runs the ``done`` function defined in
`output-adapter.common.js <https://github.com/yahoo/mojito/blob/develop/lib/app/addons/ac/output-adapter.common.js>`_,
`action-context.common.js <https://github.com/yahoo/mojito/blob/develop/lib/app/autoload/action-context.common.js>`_,
which collects metadata and configuration.

.. _dyn_dispatch-controller:
Expand Down

0 comments on commit 9d75095

Please sign in to comment.