-
Notifications
You must be signed in to change notification settings - Fork 0
0.3.0 Renderer
[new] T.Renderer() => this;
Simple data rendering from instance or static element.
Supports basic functionality works with contexts.
Not intended for use immediately! Only inheritance!
- ._data: TData
- .data(data: TData) => this
- ._context: TContext
- .context(...arguments: Array) => any
- .render(...arguments: Array<TCallback|TContext>) => T.async
- ._render(callback: TCallback, context: TContext) => void
- .toString() => string
data
Inherited when expanding with .extend.
Contains is not formatted TData.
(data: TData) => this;
Set ._data option.
Optimized way to write code in line.
var i = T.Renderer();
i.data(123).data(456);
i._data; // 456
Static.
T.Renderer.data(123);
context
(...arguments: Array<TContext>) => this;
Is used when rendering. Passed to the method Templates.renderContext.
Set ._context option.
Optimized way to write code in line.
var i = T.Renderer();
i.context({ a: 1 });
Static.
var i = T.Renderer.context({ a: 1 }).context({ b: 2 });
i._context; // { a: 1, b: 2 }
render
(...arguments: Array<TCallback{1}, TContext>) => T.async(callback: TCallback) => void;
Render the instance and all its data.
Arguments can be passed in random order.
As a result of the synchronous returns async instance.
var asyncResult = T.Renderer().data('<%= a %><%= b %>').context({ a: 123 }).render({ a: 456, b: 789 }, function(error, result) {
error; // null
result; // 456789
});
T.isAsyncFunction(asyncResult); // true
Static method.
var i1 = T.Renderer.data(123); // First instance.
var i2 = i1.extend().data(456); // Second instance extended from first instance.
var c = i2.extend(); // Extending from second instance.
c.render(console.log); // => null, 456
Contexts are merged within a call render. When rendering with this method creates a zone of visibility of context.
var i1 = T.Renderer.data('<%= a %>').context({ a: 1 });
i1.render(console.log); // null, 1
var i2 = T.Renderer.data(i1).context({ a: 2 });
i2.render(console.log); // null, 2
i2._data.render(console.log); // null, 1
var i3 = i2.extend().context({ a: 3 });
i3.render(console.log); // null, 3
i3._parent.render(console.log); // null, 2
i3._data.render(console.log); // null, 1
// If not i3, but i3.render(), context not merged.
var i4 = T.Renderer.data(i3.render()).context({ a: 4 });
i4.render(console.log); // null, 3
System method.
Does not create a zone of visibility of context.
Not intended for manual use.
() => string;
var i = T.Renderer.data(123);
var r = i.render();
i.toString(); // 123
r.toString(); // => 123
String(i); // 123
String(r); // => 123
i + ''; // 123
r + ''; // => 123
console.log(i); // 123
console.log(r); // 123
- TData: Renderer|sync|async|Mixin
- TCallback: (error, result) => void
- TSelector: string
- TInjector: () => void
- TAttributes: [name: string]: TData
- TContext: TData
Node.js:
var T = require('oswst');
Require.js:
define(['oswst'], function(T) {});
window
:
var T = window.oswst(_, async);
-
Templates
- .compile
- .include
- .render
- .renderContext
- .renderAttributes
- .renderSelector
- .sync
- .isSyncFunction
- .async
- .isAsyncFunction
- .Prototype()
- .Renderer > .Prototype
- .Data > .Renderer
- .data > .Data
- .Tag > .data
- .Single > .Tag
- .singles[string]
- .Double > .Tag
- .doubles[string]
- .Doctype > .Tag
- .doctypes[string]
- .xml > .Tag
- .Mixin > .Data
- .mixin > .Mixin
- .mixins[string]
- .Module > .Renderer
- .with