Skip to content

API Suggestion #33

Open
Open
@gfreeau

Description

@gfreeau

I want to understand why the API is just the Hydra object. What is the reason for extending the Hydra object instead of having a separate object just for the common API?

If I have this code:

Hydra.extend("hello", { say: function() { console.log('hello'); }});

Then in my module I could do this:

Hydra.module.register('adslot', ['$api'], function (api) {
        return {
            init: function () {
                api.hello.say();
            }
        };
    });

This is very intuitive, however I still do not see why "api" has to be the Hydra object instead of being it's own object or object literal. Bus is a separate object (Hydra.bus), why not API (Hydra.api)?

Then we could extend Hydra.api instead of just Hydra, I think this is better separation. The API is separate from Hydra.

In function dependencyinjection, then it would read:

oMapping = {
    '$bus': Bus,
    '$module': Hydra.module,
    '$log': ErrorHandler,
    '$api': Hydra.api,
    '$global': root,
    '$doc': root.document || null
},

As it is now, with my newly added 'hello' API property, these are the properties on the Hydra object:

  • version
  • bus
  • errorHandler
  • setErrorHandler
  • module
  • setUnblockUI
  • setDebug
  • getDebug
  • extend
  • noConflict
  • addExtensionBeforeInit
  • getCopyModules
  • getCopyChannels
  • setNamespace
  • hello

This would be much cleaner with an "api" property and then all API calls extend that. e.g Hydra.api.hello.say().

There is no difference inside module because of dependency injection, but it makes the code much easier to read and understand if you want to contribute to Hydra.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions