Skip to content

Instantly share code, notes, and snippets.

@hmans
Last active April 19, 2017 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmans/fe9ff35f68a68374ddf2baf1631b57a5 to your computer and use it in GitHub Desktop.
Save hmans/fe9ff35f68a68374ddf2baf1631b57a5 to your computer and use it in GitHub Desktop.
Inferno.js memoization decorator function using NO_OP
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}
]
{ 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