Skip to content
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

API Suggestion #33

Open
gfreeau opened this issue Jan 15, 2014 · 1 comment
Open

API Suggestion #33

gfreeau opened this issue Jan 15, 2014 · 1 comment

Comments

@gfreeau
Copy link
Contributor

gfreeau commented Jan 15, 2014

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

@tcorral
Copy link
Owner

tcorral commented Jan 15, 2014

I'll consider it for the next release.

You're welcome

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

No branches or pull requests

2 participants