Giter VIP home page Giter VIP logo

Comments (6)

nonzzz avatar nonzzz commented on August 11, 2024

theme 现在的设计就是响应式的。但是他现在的实现不是一个单例模式。如果想跨组件使用。其实是可以自己在包一层。放到一个更大的context去做这件事。

from fect.

nonzzz avatar nonzzz commented on August 11, 2024

比如我们可以创建一个hook

const globalKey = Symbol('globalState')

export const createGlobalState = () => {
  const { theme, themeChange } = useTheme()
  const state = { theme, themeChange }

  return {
    install(app) {
      app.provide(globalKey, state)
    },
  }
}

export const useGlobalState = () => inject(globalKey)

然后挂载到createAppuse方法上

from fect.

nonzzz avatar nonzzz commented on August 11, 2024

如果考虑实现单例模式。可以说下具体的原因吗。

from fect.

QiYuOr2 avatar QiYuOr2 commented on August 11, 2024

html的class是统一的,所以theme应该是全局唯一的,我已经在其他组件通过themeChange修改了html的class,但是获取到theme却是另一个,这并不合理

from fect.

nonzzz avatar nonzzz commented on August 11, 2024

@QiYuOr2 这么一看确实得这样修改. :)

from fect.

nonzzz avatar nonzzz commented on August 11, 2024

我会创建pull request. 功能会随着下个版本rc.2进行发布。

from fect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.