Skip to content

[Discussion] API to define loader hooks #62

@caridy

Description

@caridy

Discussion

Purposes:

  • The solely purpose of this issue is to convey into a solid API for the 4 hooks used by loader.

Questions:

  • How to define hooks in loader objects?
  • How to customize/wrap/specialize existing hooks?

Hooks:

  • resolve
  • fetch
  • translate
  • instantiate.

The purpose of the hook system is to provides a hookable pipeline, to allow front-end packaging solutions to hook into the loading process. E.g.: if a JavaScript program wants to translate .coffee files to JavaScript on the fly, the Loader defines a "translate" hook that can be used to get the coffee source code and transpile it into javascript before instantiation process.

note: each hook has its own signature, e.g.: fetch(key) vs translate(key, payload).

Current proposal:

// fetch hook:
// - getter
var fetchHook = loader.hook('fetch');
// - setter
loader.hook('fetch', function (key) {
    // do something here...
});

note: it is confusing. the hook concept is new, it looks like an observable, but it is not. No precedent on this kind of api AKAIK.

Simple Getter and Setters:

// fetch hook:
// - getter
var fetchHook = loader.fetch;
// - setter
loader.fetch = function (key) {
    // do something here...
});

note: the problem with this approach is that one of the hooks is called resolve, and one method of loader is also called resolve(), which is an important one.

Getter and Setters:

// fetch hook:
// - getter
var fetchHook = loader.fetchHook;
// - setter
loader.fetchHook = function (key) {
    // do something here...
});

note: the problem with this approach is that there is no precedent of the concept of hooks, it might be confusing, and on top of that it is ugly IMO.

Others

  • loader.onFetch() looks like an observable/event, which is not the case, only 1 hook can be in place.
  • loader.hookFetch same as loader.fetchHook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions