Skip to content

Add second callback parameter to updateProps #6994

@HectorRicardo

Description

@HectorRicardo

🚀 Feature

Add a second parameter callback to the updateProps function, such that it looks like:
Navigation.updateProps(props, callback).

This is to make updateProps similar to React's setState(newState, callback). The second argument is a callback that is executed once setState is completed and the component is re-rendered.

Internally, updateProps calls setState, so it's just a matter of passing that callback around.

Have you read the Contributing Guidelines on issues?

Yes

Motivation

To make updateProps similar to React's setState.

How to implement.

I digged in through the code and I believe it's just a matter of making these changes. (I am not familiar with Typescript syntax, but you'll get the idea)

On /lib/src/Navigation.ts line 191:

public updateProps(componentId: string, props: object, callback) { // add callback parameter
  this.commands.updateProps(componentId, props, callback); // pass callback
}

On /lib/src/commands/Commands.ts line 82

public updateProps(componentId: string, props: object, callback) { // add callback parameter
  this.store.updateProps(componentId, props, callback); // pass callback
  this.commandsObserver.notify(CommandName.UpdateProps, { componentId, props });
}

On /lib/src/components/Store.ts line 12:

updateProps(componentId: string, props: any, callback) { // add callback parameter
  this.mergeNewPropsForId(componentId, props);
  const component = this.componentsInstancesById[componentId];
  if (component) {
    this.componentsInstancesById[componentId].setProps(props, callback); //pass callback
  }
}

On /lib/src/components/ComponentWrapper.tsx line 52

public setProps(newProps: any, callback) { // add callback parameter
  this.setState((prevState) => ({
    allProps: {
      ...prevState.allProps,
      ...newProps,
    },
  }), callback); // pass callback
}

I could have done a pull request, but I don't have that much experience in Typescript or creating unit tests, so it would probably have been rejected.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions