These are chat archives for chandu0101/scalajs-react-components

14th
May 2016
rang
@ranglang
May 14 2016 03:00

Hi, i want to wrap Draft.js (A react Editor by Facebook),
i'm going to wrap it into my scalajs project. but i don't know how to implement the function *render and setSate. code snippet's is above

class MyEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {editorState: EditorState.createEmpty()};
    this.onChange = (editorState) => this.setState({editorState});
  }
  render() {
    const {editorState} = this.state;
    return <Editor editorState={editorState} onChange={this.onChange} />;
  }
}

ReactDOM.render(
  <MyEditor />,
  document.getElementById('container')
);

And it's mine, but i fail to update state fo Editor.

val ref_editor = Ref.toJS[EditorM]("editor")
  class Backend(scope: BackendScope[Unit, Unit]) {
    def onChange1(editorState: EditorState): Unit = {
      ref_editor(scope).foreach(e=>e.setState({MyEditorState(e.state)(editorState)}))
    }
    def render() = {
      val factory_editor = React.createFactory(Editor)
      <.div(
        factory_editor(EditorProp(ref = ref_editor,
          EditorStateStatic.createEmpty(),// how to do with this, it should be from  this.state.editorState?
          onChange = onChange1 _))
      )
    }
  }
√ėyvind Raddum Berg
@oyvindberg
May 14 2016 17:23
phew, https://github.com/chandu0101/scalajs-react-components/pull/68/files imagine doing that manually @chandu0101 xD
fixed the generator to parse react classes and methods on the component now, though its pretty much impossible to infer any types