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

[RFC] Introduce new pattern to avoid duplication of core services to extensions #1039

Merged
merged 1 commit into from
Dec 3, 2015

Conversation

cramforce
Copy link
Member

No description provided.

@cramforce
Copy link
Member Author

CC @dvoytenko @erwinmombay

@dvoytenko
Copy link
Contributor

I think this is fine. But I still wanted to @erwinmombay to comment on how easy it'd be to just do it at compilation time?

@erwinmombay
Copy link
Member

@dvoytenko can you explain again what we needed to do? just creating the installer code in a separate file?

@cramforce
Copy link
Member Author

Explicit might be better than implicit (through compiler magic) here.

@dvoytenko
Copy link
Contributor

Normally, the service code looks like this:

class History {
  // implementation
}

/**
 * @param {!Window} window
 * @return {!History}
 */
export function historyFor(window) {
  return getService(window, 'history', () => {
    return new History(window);
  });
};

We'd like to turn this to the following when compiling an extension:

/**
 * @param {!Window} window
 * @return {!History}
 */
export function historyFor(window) {
  return getService(window, 'history');
};

In short, we throw away all implementation details and keep the serviceFor method and remove the factory from it. This way, an extension would not ever compile redundant details of a service and we have no risk of an extension accidentally creating a service before main runtime.

Malte is suggesting we do this manually, but putting separate serviceFor in a separate file. But my question is whether we can do this automatically.

@cramforce
Copy link
Member Author

If we use magic the important part is to also remove all the imports!

@dvoytenko
Copy link
Contributor

Well, I'm leaning toward the manual solution as well.

@erwinmombay
Copy link
Member

right, so if we wanted to do it magically, the annotation would actually have to be on the import statement in the extension so that:

  1. we can remove the import statement.
  2. generate the serviceFor pattern embedded into the extension.

/**
* Gets service implemented in service/history-impl.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Returns service"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@erwinmombay
Copy link
Member

as far as implementation, that would be really easy to do. just depends on how comfortable we are with magic annotations 😸

@dvoytenko
Copy link
Contributor

LGTM

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

Successfully merging this pull request may close these issues.

3 participants