V
V
Valery2020-10-07 01:00:50
Programming
Valery, 2020-10-07 01:00:50

Idea reuse vs code reuse: what, when and why?

Working in one of the projects on react + redux, it turned out that I wrote my own grid component (with filtering, settings, highlighting the desired, specific output of values).

Along the way, the question arose about how redux works inside, in particular, its methods combineReducers, createStore (the ability to mix middleware), store.dispatch.

In relation to store.dispatch, I was interested in:

  • is it possible to dispatch multiple actions at once, i.e. without notifying store listeners of intermediate state changes?
  • is it possible to be notified (subscribe) when redux finishes notifying all listeners?
  • what happens if a listener subscribed to a store change in itself calls store.dispatch and is it possible to postpone it until the notification of all listeners is completed, and even collect all store.dispatch calls from listeners into one general update?


As a result of studying the source code of redux, it turned out:
  • a set of specific combineReducers methods - the idea was to describe the entire aggregate reducer in one place, clearly displaying what simple reducers it consists of and how (by what methods) they are brought together.
  • I refused to implement the store.dispatch that I was interested in. this would require a rewrite of redux, additional study of how redux-dev-utils would behave in relation to the "glued" dispatch of several actions, and most importantly, the complication of the tool, which, perhaps, goes beyond its original concept (A Predictable State Container for JS Apps).


From the review of the story above, the question posed in the title arose before me - idea reuse vs code reuse: what when and why?

A self-written grid component is an example of reusing the idea of ​​"dressed up" into specific "clothes of circumstances".

Using redux and redux-dev-tools is an example of reusing code and tools.

A set of specific methods based on combineReducers gives a variant of mixing approaches - the idea of ​​"somehow generating a reducer from constituent simpler parts" is reused and the combineReducers code underlying the specific combination methods is reused.


The question, in a more detailed form, is the statement of the problem of:
  • identifying a set of factors influencing the choice of one of the reuse options.
  • identification of selection criteria (based on the assessment of factors from the set).
  • predicting the consequences of choosing one of the options or a combination of them (partly as one of the factors influencing the choice and, partly, as a consideration of options).


In this form, the question is partly philosophical, because. implies that it has 2 parts of the answer:
  • actually philosophical - independent of specific areas of application (such as the type of application, language, libraries) and common to all of them.
  • and applied - in my example, this is a Single-page application, js, react, redux in the specifics of the project requirements

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question