70 lines
959 B
TypeScript
70 lines
959 B
TypeScript
|
|
/**
|
|
*/
|
|
interface type_output<type_result> extends lib_plankton.call.type_coproduct
|
|
{
|
|
|
|
/**
|
|
*/
|
|
render_element(
|
|
element : type_element
|
|
) : type_result
|
|
;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
let output_kind_pool : Record<
|
|
string,
|
|
(
|
|
(
|
|
data : any,
|
|
make : ((raw : any) => type_output<any>)
|
|
)
|
|
=>
|
|
type_output<any>
|
|
)
|
|
> = {};
|
|
|
|
|
|
/**
|
|
*/
|
|
function output_kind_register<type_result>(
|
|
name : string,
|
|
factory : (
|
|
(data : any, make : ((raw : any) => type_output<type_result>))
|
|
=>
|
|
type_output<type_result>
|
|
)
|
|
) : void
|
|
{
|
|
if (name in output_kind_pool)
|
|
{
|
|
throw (new Error("kind '" + name + "' already registered"));
|
|
}
|
|
else
|
|
{
|
|
output_kind_pool[name] = factory;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function output_make<type_result>(
|
|
raw : any
|
|
) : type_output<type_result>
|
|
{
|
|
if (! (raw["kind"] in output_kind_pool))
|
|
{
|
|
throw (new Error("kind '" + raw["kind"] + "' not registered"));
|
|
}
|
|
else
|
|
{
|
|
return output_kind_pool[raw["kind"]](raw["data"], output_make<type_result>);
|
|
}
|
|
}
|
|
|