ractivejs / rvc

RequireJS loader plugin for Ractive components
20 stars 10 forks source link

Components not extensible #5

Closed fskreuz closed 9 years ago

fskreuz commented 10 years ago

This is from the make function

https://github.com/ractivejs/rvc/blob/master/rvc.js#L386

                    options = {
                        template: definition.template,
                        partials: definition.partials,
                        css: definition.css,
                        components: imports
                    };

https://github.com/ractivejs/rvc/blob/master/rvc.js#L375

                            Component = Ractive.extend( options );
                        } catch ( err ) {
                            errback( err );
                            return;
                        }
                        callback( Component );
                    } else {
                        Component = Ractive.extend( options );
                        callback( Component );

Unless I'm overlooking something on the docs and readmes, this means rvc components can't extend from rvc components because

  1. The plugin uses Ractive.extend and not Parent.extend
  2. options is hard-coded in the plugin, and not the one in component.exports

It would be nice to have something like

// Non-extending
component.exports = Ractive.extend({...});

// Extending
var OtherComponent = require('rvc!nonextending');
component.exports = OtherComponent.extend({...});
Rich-Harris commented 10 years ago

Perhaps the component definition could return a base property, which is a constructor to extend from:

component.exports = {
  base: require( 'rvc!parent.html' ),
  ...
};
martypdx commented 10 years ago

What about a separate property on component with the moniker of the component to extend?

component.base = 'parent'
component.exports = {...}

@Rich-Harris Your comment just popped up. I like putting it outside the options, because it's a load thing, not an options thing.

martypdx commented 10 years ago

Could be either object or string I suppose

fskreuz commented 10 years ago

It would be nice to have it similar to the non-loader syntax. Makes it more consistent.

fskreuz commented 9 years ago

Closing this issue. Figured out that inheritance is complicated compared to just building components with configurable options.