Skip to content

🐛 fix: fix compatible with subscribe api#89

Merged
arvinxx merged 2 commits into
alphafrom
fix/compatible-subscribe
Sep 14, 2023
Merged

🐛 fix: fix compatible with subscribe api#89
arvinxx merged 2 commits into
alphafrom
fix/compatible-subscribe

Conversation

@arvinxx
Copy link
Copy Markdown
Collaborator

@arvinxx arvinxx commented Sep 14, 2023

先前一版实现,在搭配 subscribeWithSelector 时,监听能力会失效。

export const useStore = create<Store>()(
  devtools(proEditorMiddleware(subscribeWithSelector(createStore), proEditorOptions), {
    name: storeName,
  }),
);

useStore.subscribe((s) => s.data, console.log);   <- 不生效

经过排查发现之前的实现逻辑中初始化 state 的传入的方法(set,get,api),api 是解构引入的,这似乎使得 subscribeWithSelector 中间件的修改逻辑失效了:

 {
      ...api,
      // Create a new setState function as we did with set.
      setState: (partial, replace, action) => {
        api.setState(partial, replace, action);

        updateInProEditor((action as any) || {});
      },
    },

通过不修改 api 对象,换成 setState 方法的替换即可。

  const savedSetState = api.setState;
  api.setState = (partial, replace, action) => {
    savedSetState(partial, replace, action);

    updateInProEditor((action as any) || {});
  };

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Sep 14, 2023

🎊 PR Preview 349d283 has been successfully built and deployed to https://ant-design-pro-editor-preview-pr-89.surge.sh

🕐 Build time: 91.276s

🤖 By surge-preview

@arvinxx arvinxx force-pushed the fix/compatible-subscribe branch from 4e3ebfb to ebb1085 Compare September 14, 2023 06:35
@arvinxx arvinxx mentioned this pull request Sep 14, 2023
2 tasks
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (alpha@99cc3c5). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff            @@
##             alpha      #89   +/-   ##
========================================
  Coverage         ?   87.57%           
========================================
  Files            ?      350           
  Lines            ?    22494           
  Branches         ?     1034           
========================================
  Hits             ?    19698           
  Misses           ?     2796           
  Partials         ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arvinxx arvinxx merged commit 24ffb15 into alpha Sep 14, 2023
@arvinxx arvinxx deleted the fix/compatible-subscribe branch September 14, 2023 06:47
rdmclin2 pushed a commit that referenced this pull request Sep 14, 2023
## [Version&nbsp;0.21.0-alpha.1](v0.20.2...v0.21.0-alpha.1)
<sup>Released on **2023-09-14**</sup>

#### ✨ 新特性

- Undo/redo Middleware.

#### 🐛 修复

- Fix compatible with subscribeWithSelector middleware.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* Undo/redo Middleware, closes [#74](#74) ([7699738](7699738))

#### What's fixed

* Fix compatible with subscribeWithSelector middleware, closes [#89](#89) ([24ffb15](24ffb15))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 0.21.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

arvinxx added a commit that referenced this pull request Nov 24, 2023
* 🐛 fix: fix compatible with subscribe api

* ✅ test: upgrade @testing-library/jest-dom
rdmclin2 pushed a commit that referenced this pull request Nov 24, 2023
## [Version&nbsp;0.28.0-alpha.1](v0.27.0...v0.28.0-alpha.1)
<sup>Released on **2023-11-24**</sup>

#### ✨ 新特性

- Undo/redo Middleware.

#### 🐛 修复

- Fix compatible with subscribeWithSelector middleware.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* Undo/redo Middleware, closes [#74](#74) ([44551aa](44551aa))

#### What's fixed

* Fix compatible with subscribeWithSelector middleware, closes [#89](#89) ([b11cb36](b11cb36))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
rdmclin2 pushed a commit that referenced this pull request Nov 24, 2023
## [Version&nbsp;0.28.0](v0.27.0...v0.28.0)
<sup>Released on **2023-11-24**</sup>

#### ✨ 新特性

- Undo/redo Middleware.

#### 🐛 修复

- Fix compatible with subscribeWithSelector middleware.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* Undo/redo Middleware, closes [#74](#74) ([44551aa](44551aa))

#### What's fixed

* Fix compatible with subscribeWithSelector middleware, closes [#89](#89) ([b11cb36](b11cb36))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
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.

2 participants