jagi / meteor-astronomy-slug-behavior

https://atmospherejs.com/jagi/astronomy-slug-behavior
MIT License
7 stars 3 forks source link

Slug Behavior Fails on update #10

Closed zachariahtimothy closed 8 years ago

zachariahtimothy commented 8 years ago

First of all, I am IN LOVE with Astronomy! When a slug is getting updated (count > 0 in behavior.js), I receive an error:

TypeError: Cannot read property 'slugFieldName' of undefined

Debugging I found the context of "this" is lost in Class.find(selector, options).forEach(function(d) {} because function(d) is not an arrow function ("this" within the forEach is global scope). Seems like updating behavior.js line 292 to be the following would fix it.

Class.find(selector, options).forEach((d) =>  {
    let dSlug = d.get(this.options.slugFieldName);
    let dIndex = parseInt(dSlug.replace(prefix, ''), 10);
    if (dIndex >= index) {
        index = dIndex + 1;
    }
});
lukejagodzinski commented 8 years ago

Oh right, thanks for noticing it. Do you want to create PR and contribute?

zachariahtimothy commented 8 years ago

I created PR #11 but I have never created a PR before so let me know if I did it correctly. Thanks!

Genroa commented 8 years ago

Is this fixed? I have the same problem here. :)

lukejagodzinski commented 8 years ago

It's fixed. Make sure that you're using the newest package version

danopia commented 8 years ago

Git history places this fix after 2.0.0 shipped, but 2.0.0 is the latest version I see in the repo. Maybe I'm missing something?

lukejagodzinski commented 8 years ago

Hehe I forgot to publish this fix :). I've just merge PR. I will publish it in a minute

danopia commented 8 years ago

Not a huge rush, I just finished brushing up on git submodules ;)

Much appreciated though.. Astronomy is the nicest Mongo wrapper I've seen

lukejagodzinski commented 8 years ago

Published :) Thanks :)