Last active
April 19, 2017 10:56
-
-
Save hmans/fe9ff35f68a68374ddf2baf1631b57a5 to your computer and use it in GitHub Desktop.
Inferno.js memoization decorator function using NO_OP
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
memoize = require './memoize' | |
# By using memoize, the following functional component will only update | |
# when the props passed into it have changed. Please note that this assumes | |
# that the actual prop values are immutable objects, since we don't perform | |
# any deep equality checks. | |
logPanel = memoize ({log}) -> | |
h '#log-panel', [ | |
for line in log | |
h logLine, {line} | |
] |
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
{ NO_OP } = require 'inferno' | |
equals = require 'shallow-equals' | |
module.exports = (fn) -> | |
oldProps = null | |
(props) -> | |
if equals oldProps, props | |
NO_OP | |
else | |
oldProps = props | |
fn props |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment