Skip to content

Execute hook #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthewp opened this issue Apr 22, 2015 · 6 comments
Closed

Execute hook #47

matthewp opened this issue Apr 22, 2015 · 6 comments

Comments

@matthewp
Copy link

A hook just prior to execution would be extremely helpful in scenarios where you need to alter the universe for a particular module. Consider something like this:

var execute = loader.execute;
loader.execute = function(key){
  var logger = loader.lookup("logger");

  var log = logger.log;
  logger.log = function(msg){
    console.log(key + ":" + msg);
  };

  var mod = execute.apply(this, arguments);
  logger.log = log;
  return mod;
};

In this example a logger module is redefined so that it prints out the key of the module using it.

This won't work if used async but it's still quite useful.

@MajorBreakfast
Copy link

System builder's behavior to not execute modules can be implemented by setting this hook to a NOP. What you're proposing is a generalized version instead of an on/off switch. Seems useful.
https://github.com/systemjs/builder/blob/a5d76f63e4362936363de4439274a61d116f486f/lib/builder.js#L69

The instantiate hook is very similar, though. Are both needed?

@matthewp
Copy link
Author

Preventing executing for a trace is another use-case, yes.

Instantiate might be able to serve this use case. If you could return an execute function and this applies to dynamic and declarative modules, that would work. The spec is not filled out on instantiate though: http://whatwg.github.io/loader/#browser-instantiate

@caridy
Copy link
Contributor

caridy commented Jun 9, 2015

@matthewp I haven't look at this problem yet (I will), but at the first glance, there is a problem with your example, modifying the result of lookup is not allowed. Maybe you should simplify it to modify some runtime values instead of dealing with the module's dependencies.

@matthewp
Copy link
Author

matthewp commented Jun 9, 2015

Ah, yes you're right. I'll try to come up with a better example.

@caridy
Copy link
Contributor

caridy commented Aug 21, 2015

@matthewp is this still valid? do you have a better example? Otherwise let's close this.

@matthewp
Copy link
Author

I do not for the time being, let's close this and I'll reopen in the future if a good scenario comes up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants