Created
December 24, 2015 13:36
-
-
Save barneycarroll/4c395a2dafe90f4043e5 to your computer and use it in GitHub Desktop.
An idiom borrowed from React that allows Mithril components to skip view diffing if their `shouldUpdate` function returns falsey when passed view args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import remember from 'funes' | |
const retainer = { subtree : 'retain' } | |
export default remember.bind( | |
component => { | |
return 'shouldUpdate' in component | |
? { | |
...component, | |
view : ( ...args ) => | |
component.shouldUpdate( ...args ) | |
? component.view( ...args ) | |
: retainer | |
} | |
: component | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment