Skip to content

0.3.0 Renderer

Ivan S Glazunov edited this page Feb 20, 2015 · 4 revisions

sources/renderer

Templates.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

._data

TData;

Inherited when expanding with .extend.

Contains is not formatted TData.

.data

(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

._context

TContext;

.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

.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

._render

(callback: TCallback, context: TContext) => void;

System method.

Does not create a zone of visibility of context.

Not intended for manual use.

.toString

() => 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
Clone this wiki locally