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

Pre-populate calendar without having to use modifiers #247

Closed
cmrabet opened this issue Jan 17, 2017 · 1 comment
Closed

Pre-populate calendar without having to use modifiers #247

cmrabet opened this issue Jan 17, 2017 · 1 comment

Comments

@cmrabet
Copy link

cmrabet commented Jan 17, 2017

Is there anyway to "set" the days that I want selected in one shot that is not via modifiers? I'm asking this because using modifiers is slow when managing year calendars.

I have an X amount of dates stored in my database that can have different types (holiday, non workable day, etc..). I want to populate a year calendar with them using different colors depending on their type. So far I've achieved this via modifiers like so in my render method:

	// Day modifiers
		const modifiers={
	        sunday:(cellDate)=>{
	          return cellDate.getDay()==0;
	        },
	        holiday: (cellDate)=>{
	          const date=moment(cellDate).format('YYYY-MM-DD');
	          const day=_.find(this.props.calendar,(e)=>{return moment(e.date).format('YYYY-MM-DD')==date;})
	          if(day) return day.type==1;
	          else return false;
	        },
	        nonWorkable: (cellDate)=>{
	          const date=moment(cellDate).format('YYYY-MM-DD');
	          const day=_.find(this.props.calendar,(e)=>{return moment(e.date).format('YYYY-MM-DD')==date;})
	          if(day) return day.type==2;
	          else return false;
	        }         
	    };  

Where this.props.calendar is a prop populated by the parent component with the days fetched from the database via a reducer (using redux).

This is very inefficient since I have to run 365 times for X number of days for each modifier each time the component renders. It would be very nice to have a method like setDays() that admitted an array of days and their class values so we could sed in one shot only once.

Can I do this now?

Thanks.

@gpbl
Copy link
Owner

gpbl commented Feb 9, 2017

Sadly now this is not possible. I'm aware of this design performance issues, in particular this case would be solved with #181 (comment). I'd like to know your feedback on that issue!

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

2 participants