SPEAK – Sitecore concept change and pipelines

A major concept change from sheer UI to SPEAK; is that continuation/control flow has moved from the server to the client. Now the client is responsible for control flow/state validation and the server is ideally responsible for answering simple/stateless requests.

Effectively a lot of server side C# code is moving to JavaScript, and to help with the complexity and to mirror the functionality/concepts available server side, Sitecore has introduced as part of the SPEAK framework client-side pipelines.

Client Pipelines

This is a very brief introduction and I will go into more detail in follow up post.

  1. A pipeline is a set of one or more steps that can be executed in a specific order; each step shares the same context.
  2. Each step can change the context and pass it to the next step until all steps have been completed, and or the pipeline is aborted.
  3. Each step can contain both client and server side logic or just client side logic.

The diagram below illustrates a simple pipeline that is executed when a button is clicked.

Pipeline

Example

So what can we use pipeline for? well one example could be when you delete an item, the idea is to keep each step as short and sweet as possible:

  1. Step 1 – Can Delete – check if the current user has the required permissions to delete the item.
  2. Step 2 – Can Lock – the item might be locked
  3. Step 3 – Confirm – prompt the user to ensure they really want to delete the item.
  4. Step 4 – Check Clone Links – as you have to warn the user that any cloned items will become real items.
  5. Step 5 – Execute – delete the item
  6. Step 6 – Has links – show the broken link dialog to fix any broken links
  7. Step 7 – Un-clone items.

Limitations

Unfortunately the current implementation does not provide the ability to define the order the steps are executed in, using a configuration file or the web.config. The order is defined by a property called priority that is defined within the JavaScript itself, see the code below.

define(["sitecore"], function (Sitecore) {
 Sitecore.Pipelines.MyFirstPipeline = Sitecore.Pipelines.MyFirstPipeline ||
                                      new Sitecore.Pipelines.Pipeline("MyFirstPipeline");
 var myFirstPipeline =
 {
   priority: 1,
   execute: function (context) {
     console.log("My first pipeline");
   }
 };
 Sitecore.Pipelines.ValidateMessagePageLoad.add(myFirstPipeline);
});

There are number drawbacks:

  1. Each step needs to know about other steps in order to be called in the appropriate sequence.
  2. Difficult to see a clear picture for a Pipeline (in which order steps are executed).
  3. If you want to insert/remove an extra step it an existing Sitecore speak pipeline you have to modify Sitecore’s source code.
  4. It increases the complexity of upgrade.

Hope

I hope that future version of SPEAK will support declarative declaration of pipeline steps, similar to what is available server side (i.e. pipelines defined in the web.config and or include configuration files).

My next post will go into more detail about how to create and initiate pipelines, hope you enjoyed my first ever post, Alan

2 thoughts on “SPEAK – Sitecore concept change and pipelines

  1. Pingback: Making sense of SPEAK pipelines | Laub plus Co

  2. Pingback: SPEAK – Pipelines | Alan Coates - Sitecore/.NET blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s