Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created December 24, 2015 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/4c395a2dafe90f4043e5 to your computer and use it in GitHub Desktop.
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
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