question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple method calls during property updates.

See original GitHub issue

Problem:

invalidateViewHolders(), updateApapterMonthConfig() and updateAdapterViewConfig() methods are called multiple times if related properties are set in the CalendarView class.

Proposed solution:

Add an update method which will not trigger any of the above methods if properties are updated inside it. This way we avoid creating setter methods for all related properties of CalendarView.

Something like this:

open class CalendarView : RecyclerView {
	....
    private var isUpdating = false
    private var pendingAdapterMonthConfigUpdate = false
    private var pendingAdapterViewConfigUpdate = false
    private var pendingViewHolderInvalidation = false
    fun update(block: CalendarView.() -> Unit) {
        isUpdating = true
        this.block()
        isUpdating = false
        if (pendingAdapterMonthConfigUpdate) updateAdapterMonthConfig()
        if (pendingAdapterViewConfigUpdate) updateAdapterViewConfig()
        if (pendingViewHolderInvalidation) invalidateViewHolders()
		pendingAdapterMonthConfigUpdate = false
        pendingAdapterViewConfigUpdate = false
        pendingViewHolderInvalidation = false
    }
	....
}

Then the update methods will look like:

private fun updateAdapterMonthConfig() {
    if (isUpdating) {
        pendingAdapterMonthConfigUpdate = true
        return
    }
    ....
}

private fun invalidateViewHolders() {
    if (isUpdating) {
        pendingViewHolderInvalidation = true
        return
    }
    ....
}

private fun updateAdapterViewConfig() {
    if (isUpdating) {
        pendingAdapterViewConfigUpdate = true
        return
    }
    ....
}

Now using example 1 where we update a lot of configs, we can write:

animator.doOnStart {
    if (!monthToWeek) {
        binding.exOneCalendar.update { // No more => exOneCalendar.apply{}
            inDateStyle = InDateStyle.ALL_MONTHS
            maxRowCount = 6
            hasBoundaries = true
        }
    }
}

Continued from #184

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
luis-cortescommented, Jul 26, 2020

The first one is what I had in mind. However, I think maybe we should start with some of the props that have more obvious groupings like padding, margin, and height/width.

Even doing just those would be a big win I think.

0reactions
kizitonwosecommented, Jul 25, 2020

Okay, so I want to start with grouping the methods that directly cause a creating of MonthConfig since I want to allow generating the dates in the background.

This is what it looks like presently:

fun updateMonthConfiguration(
    inDateStyle: InDateStyle = this.inDateStyle,
    outDateStyle: OutDateStyle = this.outDateStyle,
    maxRowCount: Int = this.maxRowCount,
    hasBoundaries: Boolean = this.hasBoundaries
) {

}

Does the method look like what you had in mind? Or were you thinking more in the direction of something like:

fun updateMonthConfiguration(config: MonthConfig) {

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Method/Function To Update Multiple Properties Per One Control
Just pass the control. Yes; you just need to provide an argument of the appropriate type. For example: static void UpdateProperties(System.
Read more >
Is it poor practice to call methods through multiple objects?
The Law of Demeter suggests that you shouldn't call methods on objects two layers down like that. The idea is that, in your...
Read more >
Go: Call option that can be used with multiple methods
Go: Call option that can be used with multiple methods. Allow shared options in function and method calls, now with type safety! Photo ......
Read more >
Patch function in Power Apps (contains video) - Power Platform
Use the UpdateIf function to modify specific properties of multiple records based on a condition. Modify or create a set of records in...
Read more >
Class Constructor Methods - MATLAB & Simulink - MathWorks
You can suppress the assignment of the class instance to the ans variable when no output variable is assigned in a call to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found