Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

5
Ternary operator in props causing an infinite loop
Post Body

So it's Friday and I accept that my brain might not be all there but for some reason when I put a ternary operator in my props, it causes an infinite loop and breaks part of my functionality.

Background: reason I'm using a ternary is I'm rendering a table where the left column contains days "Mon, Tues, Wed" etc. I don't want a day name to appear more than once if there are more than 1 instance of that day name.

Code:

// Template
  <tbody>
    <RunInstance 
    v-for="(scheduleItem, index) in term.instances"
    :bars="bars" 
    :day="dateHasNotBeenPassed(scheduleItem) ? lastPassedDay : ''"
    :scheduleItem="scheduleItem" 
    :key="index" />
  </tbody>

// data
  data() {
    return {
      lastPassedDay: ""
    };
  },    

// checking function
dateHasNotBeenPassed(scheduleItem) {
  var date = moment.unix(scheduleItem.startDateTime).format("ddd");

  if (this.lastPassedDay != date) {
    this.lastPassedDay = date;
    return true;
  } else {
    return false;
  }
}

When I use this set up and load up the page I get the "You may have an infinite loop in the render". If I remove :day= then I don't get that error message, but my day names don't render correctly.

Anyone got an insight on what's causing the infinite loop?

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
692,980
Link Karma
149,429
Comment Karma
541,007
Profile updated: 2 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago