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

Possible bug with the auto-generated prepareView() ? #194

Open
claydodo opened this issue Oct 13, 2017 · 4 comments
Open

Possible bug with the auto-generated prepareView() ? #194

claydodo opened this issue Oct 13, 2017 · 4 comments

Comments

@claydodo
Copy link

return new subview.constructor({
parent: self
});

The auto-generated prepareView function does not provide an el argument to the constructor. As a result, the returned view instance's el may be undefined, causing container.appendChild(view.el) in renderSubview to fail. Is this a bug, or am I using it in a wrong way?

renderSubview: function (view, container) {
if (typeof container === 'string') {
container = this.query(container);
}
if (!container) container = this.el;
this.registerSubview(view);
view.render();
container.appendChild(view.el);
return view;
},

I found this issue when trying to use the example provided in ampersand-view's doc:

module.exports = AmpersandView.extend({
    ...
    subviews: {
        ...
        tab: {
            hook: 'switcher',
            constructor: ViewSwitcher
        }
    }
});
@ruiramos
Copy link
Contributor

This should not be a problem if you're trying to render an ampersand-view as a subview, but it is indeed a problem if you're "subrendering" a ViewSwitcher, as its render method needs an el to render into. (unlike regular views, they have no template)

This was indirectly caused by the big debate on whether to replace dom elements or append into them when rendering subviews, that resulted on #132 being merged in.

For now, I'd suggest you to specify a prepareView function that passes on the el when you're rendering a ViewSwitcher.

@claydodo
Copy link
Author

claydodo commented Oct 16, 2017

Thanks for the reply. I'm using the prepareView approach and it works well. However, I think this issue is indeed a paper-cut for the user (especially when they are using the built-in module according to the official document) and should be handled.

@RickButler
Copy link
Collaborator

RickButler commented Nov 18, 2017

Late to the party... @claydodo what version of view-switcher are you using? I recently made changes to it so that in conforms to the view conventions.

AmpersandJS/ampersand-view-switcher#37

Try setting view-switcher to 3.0.0 in your package.json

@claydodo
Copy link
Author

claydodo commented Dec 1, 2017

@RickButler My projects's package.json shows that the view-switcher is version 3.0.0 indeed. The problem may be the missing el of view-switcher in my case.

I'm switching from Backbone to Ampersand recently and find it extremely suitable for my need: neat data structure, nested properties and views, simple and direct logic, etc. Thanks for ALL you guys working for this library.

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

3 participants