📜 ⬆️ ⬇️

All that merge: ribosomal software architecture

image

It all starts with an example.

w //  () { function table(qIn = {}) { q["tit"] = "Wargana"; /** init- */ q["render"] = function(q){ }; qIn = merge(q, qIn); /** merge- */ if (q["m"] == "img") q = merge(q, img.table(qIn), qIn); if (q["m"] == "map") q = merge(q, gmap.table(qIn), qIn); q["render"](q); /** action- */ } } img //  1 () { function table(qIn = {}) { q["render"] = function(q) { return "img" + qIn["tit"]; }; return q; } } gmap //  2 () { function table(qIn = {}) { q["render"] = function(q) { return "map" + qIn["tit"] + this.markers(qIn); } return q; } function markers(qIn = {}) { q["layer"] = function(q) { }; qIn = merge(q, qIn); if (q["layerM"] == "cadastr") q = merge(q, cadastr.markers(qIn), qIn); return q; } } cadastr //  2.1 () { function markers(qIn = {}) { q["layer"] = function(q) { return "cadastr"; } return q; } } /** client-,  */ w.table({m : "img"}) w.table({m : "map", layerM : "cadastr"}) w.table({m : input("tableM"), layerM : input("gmapLayerM")}) 

')

Explanation of the code


  1. Parameters defaulted. Init-section sets the default value of the parameters to ensure the safe operation of the act section. At the same time, the merge section makes it difficult to arbitrarily block the parameterization of the act section.

     q = merge(q, ..., qIn); 

    In the very end of the merge list, this is a guarantee of the highest power of the client: how difficult is the code, no matter what parameter it is, the client can always “impose on his game”.

    The main thing in the scheme "Init - Merge - Act" is a bunch of "Init - Act", and Merge is secondary.

     function some(qIn = {}) { q["render"] = function(q){ return 1; }; q = merge(q, qIn); return q["render"](q); } 

    Limit init-genealogy:
     function some(){ q["render"] = function(q){ return 1; }; return q["render"](q); } 

    Exit to zero:
     function some(){ return 1; } 


  2. Grid plaginization. Using the principle of "Init - Merge - Act", the code structure can be knit to any level of nesting, because the arguments merge () 'a inside are also built on the principle of IMA.

    Interfaces

     function some(){ q["isGrab"] = 0; q = merge(q, plugSome(q)); } function plugSome(qIn = {}) { q["isGrab"] = 1; q = merge(q, qIn); return q; } 

    The init-section of the up-host some () defaulting the isGrab parameter to guarantee the safe operation of its act section (which in this case is absent) , simultaneously sets the interface for all its plug-ins connected to the merge section.

    This example illustrates, to the heap, IMA-plaginization simply on functions, while the parameter q transmitted inside the plug-in provides the above-mentioned guarantee of the highest power of the client. Of course, at any time, you can either restrict this power by performing some pre-transformations with q or even abandon the down-insertion of q into the plug-in grid.

    Namespaceing

    Grid plagiarization on a common bus creates a single namespace for the entire subgrid of plug-ins, on the one hand, creating the possibility of reusing the same signatures in different hosts, which can even be two different public functions of the same host module, for example:

     modHost { function a(){ q["isGrab"] = 0; } function b(){ q["isGrab"] = 0; } } 

    This eliminates the task of entering modHost.isGrabA, modHost.isGrabB

    On the other hand, even the most Kamchatka grid plug-in (if the grid author allows it) can use the resources of the entire parameterization up-track to build its behavior depending on the logic of the context.

    Paranoids at any time to calm the nervous system can arrange the neymspeysovy gap, abandoning the merge before retour bus:

     function a(){ q["isGrab"] = 0; q = merge(q, b(q)); } function b(qPro = {}) { q["isGrab"] = !qPro["isGrab"]; ; /* q = merge(q, qIn); */ return q; } 

    Typing

    By reducing the modeling algorithm from the modular level to the execution flow level, the type selection becomes exactly the same parameter as the parametrization of an already selected type:

     if (input.getM() == "img") imgW.table({width : 50}) 

    vs

     w.table({m : input("m"), width : 50}) 

    Hosts (as units of the meaning of the upper level) becomes smaller, the parameters become larger.


Strategies

How to add functionality


  1. copy init-section from mom's host;
  2. create a host of the plug-in of the daughter and insert the skeleton of the init section of the mother’s host;
  3. reflash each parameter or throw out if the default value suits;
  4. add a conditional merg to the daughter's host in the merge section of the mom's host;
  5. in the client section to use the new additional parameters of the usual hosts.


How to remove functionality


  1. disconnect the daughter from the mother in the merge section;
  2. rub the daughter's host.


How to produce cross-merge


 function some(qIn = {}) { // init- q["total"] = 15; // merge- // q = merge(q, someA(), someB(), qIn); qA = someA(); qB = someB(); qPro["total"] = q["total"] + qA["total"] + qB["total"] + qIn["total"]; q = merge(a, qA, qB, qIn, qPro); // act- } 

Source: https://habr.com/ru/post/206896/


All Articles