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

Assigning view collection in preLayout results in "Maximum call stack size exceeded" #901

Open
rparree opened this issue Nov 9, 2016 · 6 comments

Comments

@rparree
Copy link

rparree commented Nov 9, 2016

version

assemble 0.17.1

description

I am trying to assign a view collection to a data property on the view. I am using this technique in another project (which uses assemble-core version 0.16.0). On my current project i am trying to use assemble however.

This code works on my other project but not on my current one:

app.preRender(/\.hbs$/, function (view, next) {
    view.data.pages = app.views.decks;
    next();
});

i am getting the following error message:

Maximum call stack size exceeded

When i assign any other value to view.data.pages it does not result in an error. I need this collection to create some lists with links to other pages.

assemblefile.js

const path = require('path');
const assemble = require('assemble');
const extname = require('gulp-extname');
const app = assemble();
app.create('decks',{ layout: 'deck' });
app.decks('./src/'+'**/*.hbs');

app.preRender(/\.hbs$/, function (view, next) {
    view.data.pages = app.views.decks;
    next();
});

app.task('decks', function() {

    return app.toStream('decks')

        .pipe(app.renderFile('hbs'))
        .pipe(extname())
        .pipe(app.dest("./deck-dist-test"));

});
@assemblebot
Copy link

@rparree Thanks for the issue! If you're reporting a bug, please be sure to include:

  • The version of assemble you are using.
  • Your assemblefile.js (This can be in a gist)
  • The commandline output. (Screenshot or gist is fine)
  • What you expected to happen instead.

If your issue is related to one of the following, please open an issue there:

  • grunt-assemble Issues with using assemble in grunt or the grunt-assemble library.
  • handlebars-helpers Issues with using handlebars helpers from the handlebars-helpers library.

@rparree
Copy link
Author

rparree commented Nov 9, 2016

I am working on something like assemble/assemble-core#8 (comment)

p.s. We should add a recipe for this afterwards.

@doowb
Copy link
Member

doowb commented Nov 9, 2016

When the context is built for rendering the view, the view's data property is merged. If you add app.views.decks to view.data.pages, then this is causing a cyclical dependency on the data object.

I'd recommend using a helper to get to the collection. (or use the built-in "plural" helper):

custom helper

app.helper('collection', function(name) {
  // add some validation and error handling
  return this.app.views[name];
});
{{#each (collection 'decks')}}
{{/each}}

Built-in "plural" helper

We've been working on making this easier. The built-in helper will return a List created from the specified collection. Each view is in the .items array.

{{#decks}}
  {{#each this.items}}
  {{/each}}
{{/decks}}

I hope this is helpful.

@rparree
Copy link
Author

rparree commented Nov 9, 2016

Great!
That's really good news.

I am getting the collection using the "plurals" form.

In a previous version i used the following code to check if i was in the same "directory"/context:

{{#is dirname ../dirname}}}
  ...
{{/is}}

But even when i print :

  {{dirname}} - {{../../dirname}}

or

 {{dirname}} - {{../dirname}}

It only has a value for dirname and not for ../dirname or ../../dirname seems the outer object does not have a dirname property?

@rparree
Copy link
Author

rparree commented Nov 10, 2016

I am adding the dirname to the data myself:

app.preRender(/\.hbs$/, function (view, next) {

    view.data.dirname = view.dirname;

    next();
});

What happened to this.isCurrentPage? It seems to have been removed. This used to work:

{{#each pages}}
   <li{{#if this.isCurrentPage}} class="disabled"{{/if}}>… </li>
{{/each}}

@rparree
Copy link
Author

rparree commented Nov 10, 2016

Forget this (isCurrentPage) i am just comparing titles instead (it works for me)

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