From 0f141cb709b83ad54eed0b4d2956b844993255e6 Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 7 Dec 2013 17:14:30 +0100 Subject: [PATCH] Try to fix markdown formating issue in publish_subscribe.md --- doc/design_patterns/publish_subscribe.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/design_patterns/publish_subscribe.md b/doc/design_patterns/publish_subscribe.md index d261d45a..6d7d9696 100644 --- a/doc/design_patterns/publish_subscribe.md +++ b/doc/design_patterns/publish_subscribe.md @@ -9,12 +9,15 @@ The process can be divided in two steps: **1.** AJAX database manipulation and * 1. Example: current view `deliveries/_form` offers a link for the AJAX action `StockArticle#new`. This opens a modal filled with `stock_articles/_form`. 2. AJAX form post addresses the `StockArticle#create` action which handles the database manipulation. 3. The database manipulation is finished by the rendering of, e.g., `stock_articles/create.js.erb`. The key task there is to **publish** the database changes by calling `trigger`, i.e., + $(document).trigger({ type: 'StockArticle#create', stock_article_id: <%= @stock_article.id %> }); + 2. DOM updates for the particular view 1. Each view has the opportunity to **subscribe** to particular events of the previous step. A very simple example is the update of the `stock_articles/index` view after `StockArticle#destroy`: + $(document).on('StockArticle#destroy', function(e) { $('#stockArticle-' + e.stock_article_id).remove(); }); @@ -22,6 +25,7 @@ The process can be divided in two steps: **1.** AJAX database manipulation and * However, in most of the situations you will like to use the full power of the MVC framework in order to read new data from the database and render some partial. Let us consider this slightly more advanced case in the following. The view `stock_articles/index` could listen (amongst others) to `StockArticle#create` like this: + $(document).on('StockArticle#create', function(e) { $.ajax({ url: '#{index_on_stock_article_create_stock_articles_path}', @@ -30,4 +34,5 @@ The process can be divided in two steps: **1.** AJAX database manipulation and * contentType: 'application/json; charset=UTF-8' }); }); + 2. The action `StockArticles#index_on_stock_article_create` is a special helper action to handle DOM updates of the `stock_articles/index` view after the creation of a new `StockArticle` with the given `id`.