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

onChange and value #152

Closed
Nondv opened this issue Nov 1, 2017 · 7 comments
Closed

onChange and value #152

Nondv opened this issue Nov 1, 2017 · 7 comments

Comments

@Nondv
Copy link

Nondv commented Nov 1, 2017

Hello!
I assume that if :value attribute is constant it will be always the same.
But I can easily change value of this component:

(rum/defc  my-input []
  [:input {:on-change js/console.log :value "whatever"}])

But! if I completely remove :on-change it will be all right.
Is it expected behavior? What should I do?

@Nondv
Copy link
Author

Nondv commented Nov 1, 2017

Well, it appears that Sablono wraps elements with value (such as select and input):
it creates component around element and creates element state.

https://github.com/tonsky/sablono/blob/master/src/sablono/interpreter.cljc#L27

In short, it does not produce this:

<input value="whatever" onChange={log} />

but this:

<wrapper value="whatever" onChange={log}>
  <input value={inputState.state_value} onChange={innerOnChange} />
</wrapper>

where innerOnChange is like

function(v) {
  if(!wrapper.props.onChange) return;

  input.setState({ state_value: v })
  wrapper.props.onChange(v);
}

@Nondv
Copy link
Author

Nondv commented Nov 1, 2017

r0man/sablono#148

@tonsky
Copy link
Owner

tonsky commented Nov 2, 2017

Yeah. Inputs are a huge mess in Rum/Sablono/React integration. I hope to fix or at least clean it up one day

@rauhs
Copy link
Contributor

rauhs commented Jan 12, 2018

I think the simplest would be to throw out the wrapped components and synchronously call inst.forceUpdate() on a change to :rum/local. Then we'd just have the same behaviour as the React folks.

@tonsky
Copy link
Owner

tonsky commented Jan 12, 2018

that is true. Have to ditch sablono first though

@roman01la
Copy link
Collaborator

@Nondv Please try to repro this in 0.12.0-SNAPSHOT and report any issues to #205

@roman01la
Copy link
Collaborator

fixed in 0.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants