gobwas/dm.js

Lazy wrappers for requested objects.

Closed this issue · 6 comments

Add ability to configure objects with lazy option.

Researching for how to make promise synchronous give me nothing. Seems it could not be done in current version of JavaScript natively in browser environment. At this moment lazy feature could be useful just when all modules are bundled together and Promises are resolved, in fact, synchronously.

Bumped this to 0.3.0 milestone.

Just will be done by passing provider function to the dependent object like so:

MyObject.prototype.setDependency(dependencyProvider) {
    this.pendingDependency = dependencyProvider().then(function(dependency) {
        self.dependency = dependency;   
    });
}

Presumably, there will be new syntax symbol & inside configuration, that tells dm to wrap requested thing in a provider function, and execute parsing just on call of it:

{
    "service": {
        "path": "...",
        "arguments": ["&@dep1", "&#resource#", "&%param%", "&juststring", "&and some other %{thing}"]
    }
}

Or, the lazy option.

Do not forget about share option. Is it will be singletone pattern if share: true?