UNPKG

@loopback/docs

Version:
48 lines (30 loc) 1.09 kB
--- lang: en title: 'API docs: context.binding.todynamicvalue' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar permalink: /doc/en/lb4/apidocs.context.binding.todynamicvalue.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Binding](./context.binding.md) &gt; [toDynamicValue](./context.binding.todynamicvalue.md) ## Binding.toDynamicValue() method Bind the key to a computed (dynamic) value. <b>Signature:</b> ```typescript toDynamicValue(factoryFn: () => ValueOrPromise<T>): this; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | factoryFn | <code>() =&gt; ValueOrPromise&lt;T&gt;</code> | The factory function creating the value. Both sync and async functions are supported. | <b>Returns:</b> `this` ## Example ```ts // synchronous ctx.bind('now').toDynamicValue(() => Date.now()); // asynchronous ctx.bind('something').toDynamicValue( async () => Promise.delay(10).then(doSomething) ); ```