This project is read-only.

NOTE: I might reconsider this syntax in a future version. If you use this syntax, you might lock your code into a specific version of the library!

Reflective API

There are two API's to manage the SummaryLinkStore. On this page I describe what I've called the "Reflective API". Under the hood the functions described elsewhere are still used, and when using those functions directly I call that the "Default API". The "Default API" should support all relevant browsers, where the "Reflective API" does not support Internet Explorer 8 and older.

The reflective API should make your code more readable, but will have a slight penalty on performance and browser support.
  • Creating a SummaryLinkStore instance:
var summaryLinkStore = (oPB.sls = stringPropertyValue, oPB.sls);
stringPropertyValue should be a string value containing the SummaryLinkStore xml value (probably read from a SharePoint Summary Link web part.

The value of summaryLinkStore will be an object that supports the Reflective API for the SummaryLinkStore instance. To get to the SummaryLinkStore itself (using the Default API), you can use the instance property:
var defaultAPIInstance = summaryLinkStore.instance;
  • configuring SummaryLinkStore properties:
summaryLinkStore.columns = 3; //same as summaryLinkStore.instance.columns(3);
summaryLinkStore.groupStyle = "default"; //same as summaryLinkStore.instance.groupStyle("default");
summaryLinkStore.linkStyle = "default"; //same as summaryLinkStore.instance.linkStyle("default");
summaryLinkStore.schemaVersion = 3; //same as summaryLinkStore.instance.schemaVersion(3);
The major difference between the Default API and the Reflective API is that the Reflective API provides true properties. The accessors will still be called by the browser, but you can treat properties as properties, without calling them as functions.

Keep in mind that setting a property will throw an error if the value is invalid:
try
{
   summaryLinkStore.columns = "invalid value"; //This will throw an error!
}
catch(e) { console.log(e&&e.message||e); }
  • summaryLinks property (SummaryLinkCollection)
Both the Default API and the Reflective API will provide the same functions on the summaryLinks property. In the Reflective API you can get the items, but as Reflective API objects from the items property.
summaryLinkStore.summaryLinks.count(); //will do exactly the same as summaryLinkStore.instance.summaryLinks.count();

summaryLinkStore.summaryLinks.items[0].title; //Will do exactly the same as summaryLinkStore.instance.summaryLinks()[0].title();
  • SummaryLink instance as a reflective API object
You can use the .summaryLinks property on a reflective API object, to get SummaryLink objects using the same API.
Just like the reflective API object for the SummaryLinkStore, you can access properties using properties in stead of accessors, which are still called internally by the browser.
  • Back to a string property value
var stringPropertyValue = (summaryLinkStore + "");
Just like the Default API instance of the SummaryLinkStore, you can cast the Reflective API instance for the SummaryLinkStore to a string to get the property value.
  • Advanced behavior
A Reflective API object can be cast to a number. This number is used internally as an identifier to the object, but this will not work if you store the number (for instance in a property, argument or variable).

You can, however, use this reference inline to move an item between groups:
//This code moves the first item in the second group to the first group in the summary link store:
oPB.sls.summaryLinks.items[0].summaryLinks.items=+oPB.sls.summaryLinks.items[1].items[0];

NOTE: I might reconsider this syntax in a future version. If you use this syntax, you might lock your code into a specific version of the library!

Last edited Apr 27, 2015 at 9:25 PM by pbvansplunter, version 6