Giter Club home page Giter Club logo

blog's People

Contributors

alivedise avatar

Watchers

 avatar  avatar

blog's Issues

Detect composing when input in React

React is wrapping native dom event, but for reason it does not expose 'isComposing' for 'input' event. So what to be done here is checking evt.nativeEvent.isComposing

NOTE: this is firefox only attribute.

yarn multiple dependency upgrade issue

Case

App is importing module A, which depends on module B.
In A's package it does not specify version of package B. (Using latest)

If module B is updated from version 0.0.1 to 0.0.2, then do
|yarn upgrade A| under App's folder, nothing will happen.

Solution

  1. edit yarn.lock, find B and delete lines of B.
  2. rm -rf node_modules/B
  3. yarn

Promise.resolve will ignore all arguments except the first one

Well, I found this during debugging my Service.js

var a = function() {
  return new Promise((resolve) => {
    resolve('1', '2');
  }
}
a().then((x, y) => {
  console.log(x, y); // y is always undefined.
});

And there's no warning about it :/

So you will need to put all what you want to pass back in an array or object.

Why I dislike Redux

1. Propagate data down from root down to the leaf does not seem to make any sense

A component should only care about something it is tightly related to. There's no reason to pass down user account data in a clock component. Treat an entire desktop OS environment to be a big web application, would you give application A some data that is only needed by application B?

2. Any change of data will cause the whole application to do the re-render check.

I know React will eventually ignore any change if the newly generated virtual DOM is the same as the current virtual DOM. However it is still wasting computing power on calculating something we already know it's not needed. Since we already know what could be avoided before the computing occurs, why not reduce it? This is an important computer science skill: avoid doing some calculation that you know it's unnecessary. For example, when we want to sort ages, we will know at first that all the age values are between 0~200; thus we know we can use Radix sort instead of a pure sorting algorithm.

Someone may say: you can use a helper in React.shouldComponentUpdate to know if the data is the same as the last data. However it's still doing deep compare and is expected to spend some time.

3. A centralized event system can be achieved by other utilities

One of the biggest pros of Redux is you can see every event in the single dispatcher. However this is definitely can be done with other libraries. For example, if you are using pub/sub mechanism to do cross-component communications, you can print every pub/sub information in the pub/sub library. I am not sure why people thinks it can only be done with Redux.

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.