Object field properties #694

Closed
IwanKaramazow opened this Issue Aug 30, 2016 · 2 comments

Projects

None yet

2 participants

@IwanKaramazow
IwanKaramazow commented Aug 30, 2016 edited

For React bindings it would be nice if we could have object field properties:

  let x = {
    val field_property = "something";
    method getInitialState () => {count: 100};
    method handleClick _ => {
      let {count} = React.get_state this;
      React.set_state this {count: count + 1}
    };
    method render () => {
      let {count} = React.get_state this;
      React.createElement "div" [%bs.obj {onClick: this ## handleClick}] (string_of_int count)
    }
  } [@bs]
(* this should translate to: *)
var x = {field_property: "something", getInitialState: function() {/* ...*/} etc...}

CC @chenglou

@bobzhang
Contributor
bobzhang commented Aug 30, 2016 edited

how about the type of x should it expose field_property or not, I would say no, is it good?

@IwanKaramazow

Sounds good.

This would mainly be used in components like: (example by Chenglou)

createClass({
  _id: null,
  componentDidMount() {
    if (this.props.shouldTriggerTimeout) {
      this_id = setTimeout(this.props.callback, this.props.time);
    }
  },
  componentWillUpdate(prevProps, nextProps) {
    if (!prevProps.shouldTriggerTimeout && nextProps...) {...}
  },
  componentWillUnmount() {
    clearTimeout(this._id);
  },
  render() {return null}
})
@bobzhang bobzhang added a commit that referenced this issue Aug 30, 2016
@bobzhang bobzhang support object field #694 bddecd0
@bobzhang bobzhang added a commit that referenced this issue Sep 1, 2016
@bobzhang bobzhang support object field #694 ff6595b
@bobzhang bobzhang closed this in 9861092 Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment