Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Question about extend! #27

Open
marsanla opened this issue Aug 15, 2014 · 1 comment
Open

Question about extend! #27

marsanla opened this issue Aug 15, 2014 · 1 comment

Comments

@marsanla
Copy link

Hi it's possible to extends functionality from a file in one folder to other?. For example:

We have this structure:

- components
    - c1
        - routes.js
- core
    - c1
        - routes.js

core/c1/routes.js:

module.exports = {
   hello: function() {
       return 'hello';
   },
   world: function() {
       return 'world';
   }
};

components/c1/routes.js:

module.exports = {
   hello: function() {
       return 'welcome';
   }
};

At the end i want to get this module:

module.exports = {
   hello: function() {
       return 'welcome';
   },
   world: function() {
       return 'world';
   }
};

Should i write something in particles? Or Scatter control that?

Thanks and best regards

@mariocasciaro
Copy link
Owner

You can find in the Guide an example of how extend works: https://github.com/mariocasciaro/scatter/wiki/Guide#extend-and-override-modules

Basically, you first need to specify that the components particle extends the core particle, you can do that by specifying the override option in the particle.json of components. Then, you need to inject from components/c1/routes a reference to the overridden module, in your case c1/routes which Scatter will resolve to core/c1/routes. Next, augment the original object with your extensions. Please notice that, for obvious reasons, this mechanism works only if the extending module is a factory and receives the extended module as an argument.

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

No branches or pull requests

2 participants