2SexyContent API – Development – Code Similarity in @Razor and ...

berserkarithmeticInternet and Web Development

Dec 14, 2013 (3 years and 3 months ago)

91 views

Datei: 2SexyContent API - Development - Code Similarity Razor and JavaScript.docx Gedruckt am: 24.04.2013
2SexyContent API  Development  Code Similarity in @Razor and JavaScript
11.04.2013
Purpose of This Document
Were really keen on ensuring that concepts and code in @Razor and JavaScript look as identical
as possible. To ensure this, were keeping track of all typical actions in both languages.

Our Vision
We are convinced from now on JavaScript will play an extremely important part in output
presentation. This was so important, that we wanted to make sure that the code in @Razor and JS
looks as similar as possible, flattening the learning curve. The only relevant difference is language
specific casing-conventions and some shortcuts.

Version Info
Version
Responsible Person and Role
Comments
EN 2013.03
2013-04-11
Daniel Mettler, CEO 2sic Internet Solutions
Software Architect 2SexyContent
Work in Progress

Table of Contents
1. Code Similarity for Streams/Lists in @Razor and JavaScript ..................................... 2
1.1. Building Sources and Loading Data ............................................................... 2
1.2. Accessing Streams, Lists and In-Lists (todo: default stream) ............................... 3
1.3. Querying Stream Configuration [not implemented] ............................................ 3


Datei: 2SexyContent API - Development - Code Similarity Razor and JavaScript.docx Gedruckt am: 24.04.2013
1. Code Similarity for Streams/Lists in @Razor and JavaScript
1.1. Building Sources and Loading Data
Action
Code in @Razor and C#
Code in JavaScript
Create/Get current
Module-Controller
// (not available/necessary, as the @Razor already operates
inside this controler context)
var cont = $2sc(17); // its get-or-create the module 17
Get main data sources
var data = Data; var data = cont.data; // or $2sc(17).data;
Attach to pre-
configured source
Not available/necessary, is already done by 2SexyContent Not available/necessary, happens automatically
Attach a custom source
Data = CreateSource("..."); // not recommended, but works
cont.data = cont.createSource(...); // not implemented yet
Create Source
var allS = CreateSource(); // or CreateSource("");
var filterS = CreateSource("....EntityTypeFilter");
var reFilter = CreateSource("...Filter", filterS);
var newS = CreateSource([TypeName][,inSource]);
// default in is app data Cache
// note: this is optional in JS, as it auto-configures to def. source
var newS = cont.createSource([, TypeName][, inSource]);
// default source is upstream webserver
// not yet implemented
Attach In-Source
w/all streams
newS.Attach(inSource);
// not necessary if default source (all app-data) is ok
newS.attach(inSource);
// not necessary for default AJAX/JSON
Attach 1 In-Stream
newS.In[inName] = inS["EventStream"];

newS.in[inName] = inS["EventStream"]; // not yet implemented

Load Data
not available (automatic) data.load();
On Load
not available (automatic) data.on("load", event(){});
Main Source
var dataSource = Data; // source inside the @Razor var dataSource = cont.data; // from controller
var dataSource = $2sc(17).data; // from controller
...
Attach Stream to Main
Source
Data.In["name"] = xxx data.in["name"] = xxx;
// probably never needed in JS

1.1.1. Discrepancies
 CreateSource once has a controller (js), once not (c#)  todo 2rm

1.2. Accessing Streams, Lists and In-Lists (todo: default stream)
Action
Code in @Razor and C#
Code in JavaScript

Problem: Default
stream

List; // not a Stream-List!?
Data["Content"].List
var List = CreateBundleList(Data.In, "Content", "Presentation");

Get Named Stream
var st = Data.In["Events"]; // from def.source
var st = s.In["Events"]; // from own source variable
var st = data.in["Events"];
var st = cont.data.in["Events"]; // controller also $2sc(17).
In-List
var list = Data.In["Events"].List; var list = data.in["Events"].list;
In-Source
var inS = Data.In["Events"].Source; var inS = data.in["Events"].source;
In-Listname
var n = Data.In["Events"].Name;
//  EventStream
var n = data.in["Events"].name;
//  EventStream
In-Stream List
var inList = Data.In["Events"].List; var inList = data.in["Events"].list;
Out List (not needed)
var l = s["Events"].List;
var l = s["Events"].list; // not implemented, out not available
Out Stream Host
var h = s["Events"].Source; //  s
var h2 = s.Out["Events"].Source; //  s
var h = s["Events"].source; //  s
var h2 = s.out["Events"].source; //  s
Out Stream Name
var n = s["Events"].Name //  Events
var n = s.Out["Events"].Name //  Events
var n = s["Events"].name //  Events
var n = s.out["Events"].name //  Events

1.3. Querying Stream Configuration [not implemented]
Action
Code in @Razor and C#
Code in JavaScript
In-Stream is available
s.In.ContainsKey("Events"); s.hasIn("Events"); // not used in JS
Stream-Info
s["Events"].Description; // some notes s["Events"].description; // notes, not used
In is required
s.In["Events"].IsRequired;
s["Events"].isRequired; // not used in JS
In-Stream is loaded
s.In["Events"].IsLoaded; // not yet impl
// true if attached
s.in["Events"].isLoaded;
// true if attached & loaded
Out-Stream is available
s.Out.ContainsKey("Events");
// true if configured
s.Out["Events"] != undefined;
// true if configured
Stream has entities
(latr)
s["Events"].HasEntities; // true/false
s["Events"].hasEntities; // true/false