Skip to content

新版本scope特性被移除了? #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wangmingxu opened this issue Jan 3, 2020 · 2 comments
Closed

新版本scope特性被移除了? #114

wangmingxu opened this issue Jan 3, 2020 · 2 comments

Comments

@wangmingxu
Copy link

新版本里useAyanami不支持传入scope了,是基于什么考虑去掉了这个特性呢?后续有没有替代方案支持组件间的数据隔离

@Brooooooklyn
Copy link
Contributor

Scope 特性让 Ayanami 的底层设计变得非常复杂,并且会极大的影响 SSR 性能。
新版下数据隔离可以设计在 State 中,配合新增的 Selector API 可以做到更细粒度的组件更新控制:

interface ScopedState {
  foo: string
  bar: number
}

interface State {
 [index: string]: ScopedState
}

@Module('Somenamespace')
class SomeModule extends Ayanami<State> {
  defaultState = {}
}

const { params: { id } } = useRouter()
useAyanami(SomeModule, {
 selector: (state) => state[id],
 mutateStateOnFirstRendering: (state: Draft<State>) => {
   if (!state[id]) {
     state[id] = defaultState
   }
 }
})

@Brooooooklyn
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants