mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
incorporate kegan PR feedback
This commit is contained in:
parent
2a64d0feb3
commit
17fdfa0c8f
2 changed files with 25 additions and 8 deletions
|
@ -41,9 +41,6 @@ module.exports = React.createClass({
|
||||||
Edit: "edit",
|
Edit: "edit",
|
||||||
},
|
},
|
||||||
|
|
||||||
value: '',
|
|
||||||
placeholder: false,
|
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
return {
|
return {
|
||||||
onValueChanged: function() {},
|
onValueChanged: function() {},
|
||||||
|
@ -69,6 +66,13 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillMount: function() {
|
||||||
|
// we track value as an JS object field rather than in React state
|
||||||
|
// as React doesn't play nice with contentEditable.
|
||||||
|
this.value = '';
|
||||||
|
this.placeholder = false;
|
||||||
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.value = this.props.initialValue;
|
this.value = this.props.initialValue;
|
||||||
if (this.refs.editable_div) {
|
if (this.refs.editable_div) {
|
||||||
|
@ -76,9 +80,6 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate: function() {
|
|
||||||
},
|
|
||||||
|
|
||||||
showPlaceholder: function(show) {
|
showPlaceholder: function(show) {
|
||||||
if (show) {
|
if (show) {
|
||||||
this.refs.editable_div.textContent = this.props.placeholder;
|
this.refs.editable_div.textContent = this.props.placeholder;
|
||||||
|
|
|
@ -168,6 +168,9 @@ module.exports = React.createClass({
|
||||||
oldAliases[domain] = alias_events[i].getContent().aliases.slice(); // shallow copy
|
oldAliases[domain] = alias_events[i].getContent().aliases.slice(); // shallow copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this whole delta-based set comparison function used for domains, aliases & tags
|
||||||
|
// should be factored out asap rather than duplicated like this.
|
||||||
|
|
||||||
// work out whether any domains have entirely disappeared or appeared
|
// work out whether any domains have entirely disappeared or appeared
|
||||||
var domainDelta = {}
|
var domainDelta = {}
|
||||||
Object.keys(oldAliases).forEach(function(domain) {
|
Object.keys(oldAliases).forEach(function(domain) {
|
||||||
|
@ -208,9 +211,15 @@ module.exports = React.createClass({
|
||||||
ops.push({ type: "put", alias: alias });
|
ops.push({ type: "put", alias: alias });
|
||||||
} else if (delta[alias] == -1) {
|
} else if (delta[alias] == -1) {
|
||||||
ops.push({ type: "delete", alias: alias });
|
ops.push({ type: "delete", alias: alias });
|
||||||
|
} else {
|
||||||
|
console.error("Calculated alias delta of " + delta[alias] +
|
||||||
|
" - this should never happen!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error("Calculated domain delta of " + domainDelta[domain] +
|
||||||
|
" - this should never happen!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -237,6 +246,9 @@ module.exports = React.createClass({
|
||||||
ops.push({ type: "put", tag: tag });
|
ops.push({ type: "put", tag: tag });
|
||||||
} else if (delta[tag] == -1) {
|
} else if (delta[tag] == -1) {
|
||||||
ops.push({ type: "delete", tag: tag });
|
ops.push({ type: "delete", tag: tag });
|
||||||
|
} else {
|
||||||
|
console.error("Calculated tag delta of " + delta[tag] +
|
||||||
|
" - this should never happen!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -286,7 +298,11 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onAliasDeleted: function(domain, index) {
|
onAliasDeleted: function(domain, index) {
|
||||||
// XXX: can we edit state directly and then set, or should we copy it first?
|
// It's a bit naughty to directly manipulate this.state, and React would
|
||||||
|
// normally whine at you, but it can't see us doing the splice. Given we
|
||||||
|
// promptly setState anyway, it's just about acceptable. The alternative
|
||||||
|
// would be to arbitrarily deepcopy to a temp variable and then setState
|
||||||
|
// that, but why bother when we can cut this corner.
|
||||||
var alias = this.state.aliases[domain].splice(index, 1);
|
var alias = this.state.aliases[domain].splice(index, 1);
|
||||||
this.setState({
|
this.setState({
|
||||||
aliases: this.state.aliases
|
aliases: this.state.aliases
|
||||||
|
|
Loading…
Reference in a new issue