Giter Site home page Giter Site logo

typescript-vite-valtio-use-class-as-state-management-demo's Introduction

TypeScript Vite Valtio Use Class as State Management Demo

由于真正工作的是proxy,所以如果引用到了非proxy字段,就不会起作用。这个问题在class中尤为突出。

几个注意点:

  1. class中的method要使用function风格而非=>风格,因为前者的this是动态的,使用时会正确的指向proxy对象;而后者将永远指向原来未被proxy的对象,修改将不起作用
  2. 使用store时,必须使用 store.action风格,而不能先解构为 const {action} = store; action()。因为这种情况下,proxy也会失效。

所以最好按这里提示的方法来组织 actions: https://github.com/pmndrs/valtio/wiki/How-to-organize-actions

npm install
npm start

It will open page on browser automatically.

typescript-vite-valtio-use-class-as-state-management-demo's People

Contributors

freewind avatar

Watchers

James Cloos avatar

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.