Skip to content

Commit

Permalink
* (bluefox) Added method onStateUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 15, 2022
1 parent a7da7ca commit 0ad8241
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ See here: https://github.com/ioBroker/ioBroker.vis-2-widgets-react-template
-->

## Changelog
### **WORK IN PROGRESS**
* (bluefox) Added method onStateUpdated

### 0.3.1 (2022-08-04)
* (bluefox) Added search for i18n keys in the tooltips

Expand Down
8 changes: 6 additions & 2 deletions searchI18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function findKeys(src, name) {
ecmaVersion: 'latest'
});

walk.full(result, node => {
walk.fullAncestor(result, (node, state, ancestors) => {
if (node.type === 'CallExpression' && node.callee.property?.type === 'Identifier' && node.callee.property?.name === 't') {
if (node.arguments.length === 1 && node.arguments[0].type === 'Literal' && typeof node.arguments[0].value === 'string') {
// This is for the case `t` is called with a single string
Expand Down Expand Up @@ -63,7 +63,11 @@ function findKeys(src, name) {
}
} else
if (node.type === 'Property' && node.key.name === 'tooltip') {
if (!keys.includes(node.value.value)) {
if (ancestors[ancestors.length - 7] &&
ancestors[ancestors.length - 7].key &&
ancestors[ancestors.length - 7].key.name === 'visAttrs' &&
!keys.includes(node.value.value)
) {
keys.push(node.value.value);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/visRxWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class visRxWidget extends React.Component {

}

// eslint-disable-next-line class-methods-use-this
// @ts-ignore
onStateUpdated(id, state) {

}

getIdSubscribeState = (id, cb) => {
return this.props.socket.getState(id)
.then(result => {
Expand All @@ -37,6 +43,9 @@ class visRxWidget extends React.Component {
const values = JSON.parse(JSON.stringify(this.state.values));
Object.keys(state).forEach(key =>
values[`${id}.${key}`] = state[key]);

this.onStateUpdated(id, state);

this.setState({ values });
}

Expand Down

0 comments on commit 0ad8241

Please sign in to comment.