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.
- A pipeline is a set of one or more steps that can be executed in a specific order; each step shares the same context.
- 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.
- 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.
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:
- Step 1 – Can Delete – check if the current user has the required permissions to delete the item.
- Step 2 – Can Lock – the item might be locked
- Step 3 – Confirm – prompt the user to ensure they really want to delete the item.
- Step 4 – Check Clone Links – as you have to warn the user that any cloned items will become real items.
- Step 5 – Execute – delete the item
- Step 6 – Has links – show the broken link dialog to fix any broken links
- 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:
- Each step needs to know about other steps in order to be called in the appropriate sequence.
- Difficult to see a clear picture for a Pipeline (in which order steps are executed).
- If you want to insert/remove an extra step it an existing Sitecore speak pipeline you have to modify Sitecore’s source code.
- 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