Skip to content

refactor: keep the word cloud shape tap as a stable member callback - #4680

Merged
xile611 merged 1 commit into
VisActor:developfrom
g1f9:refactor/wordcloud-shape-tap-member-callback
Sep 14, 2026
Merged

refactor: keep the word cloud shape tap as a stable member callback#4680
xile611 merged 1 commit into
VisActor:developfrom
g1f9:refactor/wordcloud-shape-tap-member-callback

Conversation

@g1f9

@g1f9 g1f9 commented Sep 14, 2026

Copy link
Copy Markdown

🤔 This is a ...

  • Refactoring

🔗 Related issue link

Follow-up to #4679 (fix #4649).

🔗 Related PR link

#4679

🐞 Bugserver case id

💡 Background and solution

#4679 landed the word cloud shape tap lifecycle fix, but it kept a { stage, fn } record on the series so that release() could still reach the stage after the fact:

protected _afterWordcloudShapeDrawTap?: { stage: IStage; fn: () => void };

That record is unnecessary. hooks.afterRender is declared as SyncHook<[IStage]>, so a tap already receives the stage it runs on — the same signature Stage uses for its own constructor tap (this.afterRender = stage => { ... }).

So the callback can simply be a member with a stable identity:

const AFTER_WORDCLOUD_SHAPE_DRAW_TAP = 'afterWordcloudShapeDraw';

protected _afterWordcloudShapeDraw = (stage: IStage) => {
  stage.hooks.afterRender.unTap(AFTER_WORDCLOUD_SHAPE_DRAW_TAP, this._afterWordcloudShapeDraw);

  const globalInstance = this._option?.globalInstance;
  if (!globalInstance) {
    return;
  }
  this._option.dispatchEvent?.(ChartEvent.afterWordcloudShapeDraw, { instance: globalInstance });
  globalInstance.getChart().getOption().performanceHook?.afterWordcloudShapeDraw?.(globalInstance);
};

The three places that need a stage each already have one:

where stage comes from
the tap unregistering itself the stage argument the hook passes in
re-registering after a new layout the local stage already resolved in onLayoutFinished
release() this._option?.globalInstance?.getStage()_option is only cleared by super.release(), which runs after

A stable member identity is also exactly what unTap(name, fn) wants, so the fn argument requested in the #4679 review is preserved: a stage hosting more than one word cloud series still only drops its own callback.

This deletes the _afterWordcloudShapeDrawTap field and the _removeAfterWordcloudShapeDrawTap helper, and moves the tap name into one module constant so registration and removal cannot drift apart.

📝 Changelog

Internal refactor, no behavior change — no changelog entry ("type": "none").

Language Changelog
🇺🇸 English
🇨🇳 Chinese

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Verified: word-cloud-shape-release.test.ts (removal on release, no duplicate registration) and the two background cases in update-spec.test.ts all pass; tsc --noEmit clean; prettier clean.

Follow-up to VisActor#4679.

`hooks.afterRender` is declared as `SyncHook<[IStage]>`, so a tap already receives
the stage it runs on — the same way `Stage` registers its own `constructor` tap.
That removes the need to remember `{ stage, fn }` on the series: the callback is a
member with a stable identity, it unregisters itself from the stage it is handed,
and `release()` reaches the stage through `_option`, which is still alive before
`super.release()` clears it.

Drops the `_afterWordcloudShapeDrawTap` field and the
`_removeAfterWordcloudShapeDrawTap` helper, and moves the tap name into a single
module constant so registration and removal cannot drift apart.

No behavior change: the existing word cloud tap tests still cover removal on
release and the absence of duplicate registrations.
@xile611
xile611 merged commit 4a51ea6 into VisActor:develop Sep 14, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] updateSpec: background is not re-rendered when spec.background and spec.theme change in the same call

3 participants