Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make debounce specific to the instance #68

Conversation

sslotsky
Copy link

Resubmission of #49

Elected to resubmit rather than rebase because

  1. Code was extremely stale
  2. Easier to undo my changes to the lib folder, which I assume you don't want

Also noticed that #66 proposes the same change as this does, but it also needs rebasing. @JedWatson I'll leave it up to you which one you prefer, but assuming you use this one, let's get it before it goes stale again!

@obrok
Copy link

obrok commented Sep 21, 2016

@JedWatson could you post a notification in this PR when/if you release this?

@chungeunkim
Copy link

+1

@sslotsky
Copy link
Author

sslotsky commented Nov 7, 2016

@JedWatson this has gone stale again. Are you not watching this repo?

@alpacaaa
Copy link

Thanks @sslotsky for the patch. For anyone in need of a quick hack, here's what I'm using:

import debounce from 'lodash.debounce'

class PatchedCodeMirror extends CodeMirror {
  constructor() {
    super()
    this.handleUpdate = debounce(function(nextProps) {
      if (this.codeMirror && nextProps.value !== undefined && this.codeMirror.getValue() !== nextProps.value) {
        this.codeMirror.setValue(nextProps.value)
      }
      if (typeof nextProps.options === 'object') {
        for (let optionName in nextProps.options) {
          if (nextProps.options.hasOwnProperty(optionName)) {
            this.codeMirror.setOption(optionName, nextProps.options[optionName])
          }
        }
      }
    }, 0)
  }

  componentWillReceiveProps(nextProps) {
    this.handleUpdate(nextProps)
  }
}

Hopefully this will get merged soon 😕

@JedWatson
Copy link
Owner

Hey @sslotsky sorry for the delay - I believe a valid fix for this has already been merged: see https://github.com/JedWatson/react-codemirror/blob/master/src/Codemirror.js#L39

componentWillMount () {
	this.componentWillReceiveProps = debounce(this.componentWillReceiveProps, 0);
},

If that doesn't work for you, I'll replace it with the method in this PR - let me know.

Thanks!

@JedWatson
Copy link
Owner

by the way, I've just published 0.3.0 including a fix that I think works

@alpacaaa
Copy link

@JedWatson can confirm 0.3.0 works as expected, thanks!

@JedWatson JedWatson closed this May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants