Skip to content

Commit

Permalink
feat(troika-core): add update convenience method to all facades
Browse files Browse the repository at this point in the history
For usage ala React's setState. Really just a shortcut for assigning
some props and invoking the proper lifecycle responses.
  • Loading branch information
lojjic committed May 29, 2020
1 parent 2761f39 commit 7403be1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/troika-core/src/facade/Facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export default class Facade {
this.parent = parent
}

/**
* Performs a manual update of this facade, invoking the afterUpdate lifecycle method and triggering a
* render. This can be called in event handlers, for example, to affect changes to this facade and its
* subtree. This process is synchronous. Never override this method as a way to react to updates, as it
* is not the only way a component is updated; instead override `afterUpdate` or use setters.
* @param {object} props - A set of properties to be copied to the facade
*/
update(props) {
if (props && typeof props === 'object') {
assign(this, props)
this.afterUpdate()
this.notifyWorld('needsRender')
}
}

/**
* Called at the end of an update batch, after all individual properties have been assigned.
*/
Expand Down

0 comments on commit 7403be1

Please sign in to comment.