html – interact with SVG Marker element with event handlers in React(JS)

see demo: https://codesandbox.io/s/svg-marker-element-ekkkx?file=/src/App.js
as you can see – the events on the marker element just do not fire.

what can do to make it work, or any idea for an easy alternative implementing arrowhead without the use of SVG marker elements, or any sort of workaround?

(you can see a more detailed explanation of the problem here )

Unity – Make handlers visible when loading the scene

In my development environment, I have a couple of custom handlers that I always want to have visible.

I have already found out that I can do this by deriving a class from the editor, linking it to the desired component type and then appending the rendering method to SceneView.duringSceneGui (in OnEnable () because the target information about the game object is available there) .

However, this attachment only takes place when a certain game object has been selected with the component. Is there a way to properly trigger the editor's OnEnable () method when opening a scene for all relevant game objects without first manually selecting them?

PHP router system like Laravel, how do you manage route creation and router handlers?

I am trying to create a URL router system for educational purposes that has a similar use to Laravel, but I am curious to see how I can register the routes as with Laravel (with individual calls to static methods) "conceptual" code that I use with a TDD approach:

        $Route = new Route;
        $Route
        ->setUri('users/(i:id)')
        ->setMethod('GET')
        ->setCallback(function () {
            return 'get user';
        })
        ->setMiddleware((
            AppHttpMiddlewaresAuth::class,
            AppHttpMiddlewaresPermission::class
        ))
        ->setName('users.show');

        $Route2 = new Route;
        $Route2
        ->setUri('orders')
        ->setMethod('POST')
        ->setCallback('OrdersController@create')
        ->setMiddleware((
            AppHttpMiddlewaresAuth::class
        ))
        ->setName('orders.post');

        $Router = new Router;
        $Router->addRoute($Route);
        $Router->addRoute($Route2);
        // if the route is matched this methods are called
        // $Router->handleMiddlewares();
        // $Router->handleCallback();
        $Router->run();

1 – Is there a better way to encapsulate the creation of route objects in a simple / shorter way?
e.g .:
In Laravel we can map routes as follows:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback)->name('foo');

2 – Should the router class be responsible for filtering routes (regex rules, etc.), handling callbacks, and middleware?

Performance – Improvements to JQuery event handlers and IF statements

First of all, not the best with JQuery, but know enough to deal with it. I have a custom script for our WordPress site that is linked to a main plugin we use. I have a JSfiddle app that contains a list of tasks in addition to the staging site. My main goal at the moment is to improve the code. The main thing is to cut the fat and reduce the waiting time for the page to display properly.

Here is the JS

jQuery(function ($) {
    // Create Variables
    var stains = $(".stains-container");
    var radio_buttons = $("input(name='tmcp_radio_0'), input.wood-class");

    // Check if Oak is checked
    var oak_checked         = $(":radio(value^=Oak_), :radio(value*=Oak_), :radio(value^=Barnwood_)").is(":checked");
    var $oakchecked         = $("input.b-maple-stains, input.cherry-stains, input.qswo-stains, input.h-maple-stains, input.hickory-stains, input.walnut-stains");
    var $oakactive          = $(".b-maple-stains-div li, .cherry-stains-div li, .qswo-stains-div li, .h-maple-stains-div li, .hickory-stains-div li, .walnut-stains-div li");
    var $oakactivehide      = $(".b-maple-stains-div, .cherry-stains-div, .qswo-stains-div, .h-maple-stains-div, .hickory-stains-div, .walnut-stains-div");
    // Check if B. Maple is checked
    var bmaple_checked      = $(":radio(value^=Brown), :radio(value^=Wormy)").is(":checked");
    var $bmaplechecked      = $("input.oak-stains, input.cherry-stains, input.qswo-stains, input.h-maple-stains, input.hickory-stains, input.walnut-stains");
    var $bmapleactive       = $(".oak-stains-div li, .cherry-stains-div li, .qswo-stains-div li, .h-maple-stains-div li, .hickory-stains-div li, .walnut-stains-div li");
    var $bmapleactivehide   = $(".oak-stains-div, .cherry-stains-div, .qswo-stains-div, .h-maple-stains-div, .hickory-stains-div, .walnut-stains-div");
    // Check if Cherry is checked
    var cherry_checked      = $(":radio(value^=Cherry_), :radio(value*=Cherry_)").is(":checked");
    var $cherrychecked      = $("input.oak-stains, input.b-maple-stains, input.qswo-stains, input.h-maple-stains, input.hickory-stains, input.walnut-stains");
    var $cherryactive       = $(".oak-stains-div li, .b-maple-stains-div li, .qswo-stains-div li, .h-maple-stains-div li, .hickory-stains-div li, .walnut-stains-div li");
    var $cherryactivehide   = $(".oak-stains-div, .b-maple-stains-div, .qswo-stains-div, .h-maple-stains-div, .hickory-stains-div, .walnut-stains-div");
    // Check if QSWO is checked
    var qswo_checked        = $(":radio(value^=Quartersawn)").is(":checked");
    var $qswochecked        = $("input.oak-stains, input.b-maple-stains, input.cherry-stains, input.h-maple-stains, input.hickory-stains, input.walnut-stains");
    var $qswoactive         = $(".oak-stains-div li, .b-maple-stains-div li, .cherry-stains-div li, .h-maple-stains-div li, .hickory-stains-div li, .walnut-stains-div li");
    var $qswoactivehide     = $(".oak-stains-div, .b-maple-stains-div, .cherry-stains-div, .h-maple-stains-div, .hickory-stains-div, .walnut-stains-div");
    // Check if H. Maple is checked
    var hmaple_checked      = $(":radio(value^=Hard), :radio(value*=Hard)").is(":checked");
    var $hmaplechecked      = $("input.oak-stains, input.b-maple-stains, input.cherry-stains, input.qswo-stains, input.hickory-stains, input.walnut-stains");
    var $hmapleactive       = $(".oak-stains-div li, .b-maple-stains-div li, .cherry-stains-div li, .qswo-stains-div li, .hickory-stains-div li, .walnut-stains-div li");
    var $hmapleactivehide   = $(".oak-stains-div, .b-maple-stains-div, .qswo-stains-div, .cherry-stains-div, .hickory-stains-div, .walnut-stains-div");
    // Check if Hickory is checked
    var hickory_checked     = $(":radio(value^=Hickory_), :radio(value*=Hickory_)").is(":checked");
    var $hickorychecked     = $("input.oak-stains, input.b-maple-stains, input.cherry-stains, input.qswo-stains, input.h-maple-stains, input.walnut-stains");
    var $hickoryactive      = $(".oak-stains-div li, .b-maple-stains-div li, .cherry-stains-div li, .qswo-stains-div li, .h-maple-stains-div li, .walnut-stains-div li");
    var $hickoryactivehide  = $(".oak-stains-div, .b-maple-stains-div, .qswo-stains-div, .h-maple-stains-div, .cherry-stains-div, .walnut-stains-div");
    // Check if Walnut is checked
    var walnut_checked     = $(":radio(value^=Walnut_), :radio(value*=Walnut_)").is(":checked");
    var $walnutchecked     = $("input.oak-stains, input.b-maple-stains, input.cherry-stains, input.qswo-stains, input.h-maple-stains, input.hickory-stains");
    var $walnutactive      = $(".oak-stains-div li, .b-maple-stains-div li, .cherry-stains-div li, .qswo-stains-div li, .h-maple-stains-div li, .hickory-stains-div li");
    var $walnutactivehide  = $(".oak-stains-div, .b-maple-stains-div, .qswo-stains-div, .h-maple-stains-div, .cherry-stains-div, .hickory-stains-div");

    // Hide stains unless a wood is chosen
    if(oak_checked) {
        $(".oak-stains-div").show();
        $oakactivehide.hide();
        $oakchecked.prop('checked', false);
        $oakactive.removeClass( "tc-active" );
    } else if(bmaple_checked) {
        $(".b-maple-stains-div").show();
        $bmapleactivehide.hide();
        $bmaplechecked.prop('checked', false);
        $bmapleactive.removeClass( "tc-active" );
    } else if(cherry_checked) {
        $(".cherry-stains-div").show();
        $cherryactivehide.hide();
        $cherrychecked.prop('checked', false);
        $cherryactive.removeClass( "tc-active" );
    } else if(qswo_checked) {
        $(".qswo-stains-div").show();
        $qswoactivehide.hide();
        $qswochecked.prop('checked', false);
        $qswoactive.removeClass( "tc-active" );
    } else if(hmaple_checked) {
        $(".h-maple-stains-div").show();
        $hmapleactivehide.hide();
        $hmaplechecked.prop('checked', false);
        $hmapleactive.removeClass( "tc-active" );
    } else if(hickory_checked) {
        $(".hickory-stains-div").show();
        $hickoryactivehide.hide();
        $hickorychecked.prop('checked', false);
        $hickoryactive.removeClass( "tc-active" );
    } else if(walnut_checked) {
        $(".walnut-stains-div").show();
        $walnutactivehide.hide();
        $walnutchecked.prop('checked', false);
        $walnutactive.removeClass( "tc-active" );
    } else if(radio_buttons.is(":not(:checked)")) {
        $(".stains-container").hide();
    } 

    // Check if Oak is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var oakRegExp = /^Oak_d$/;
      var reclaimedOakRegExp = /^Reclaimed Oak_d$/;
      var barnwoodOakRegExp = /^Reclaimed Barnwood_d$/;
      var rstHckOakRegExp = /^Rustic Hickory Twigs and Oak_d$/;

      if (oakRegExp.test(e.target.value) || reclaimedOakRegExp.test(e.target.value) || barnwoodOakRegExp.test(e.target.value) || rstHckOakRegExp.test(e.target.value)) {
        stains.show();
        $(".oak-stains-div").show();
        $oakchecked.prop('checked', false);
        $oakactive.removeClass("tc-active");
      } else {
        $(".oak-stains-div").hide();
      }
    });

    // Check if B. Maple is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var brownMapleRegExp = /^Brown Maple_d$/;
      var wormyMapleRegExp = /^Wormy Maple_d$/;

      if (brownMapleRegExp.test(e.target.value) || wormyMapleRegExp.test(e.target.value)) {
        stains.show();
        $(".b-maple-stains-div").show();
        $bmaplechecked.prop('checked', false);
        $bmapleactive.removeClass("tc-active");
      } else {
        $(".b-maple-stains-div").hide();
      }
    });

    // Check if Cherry is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var cherryRegExp = /^Cherry_d$/;
      var rusticCherryRegExp = /^Rustic Cherry_d$/;
      var rusticHickoryCherryRegExp = /^Rustic Hickory Twigs and Cherry_d$/;

      if (cherryRegExp.test(e.target.value) || rusticCherryRegExp.test(e.target.value) || rusticHickoryCherryRegExp.test(e.target.value)) {
        stains.show();
        $(".cherry-stains-div").show();
        $cherrychecked.prop('checked', false);
        $cherryactive.removeClass( "tc-active" );
      } else {
        $(".cherry-stains-div").hide();
      }
    });

    // Check if QSWO is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var qswoRegExp = /^Quartersawn White Oak_d$/;

      if (qswoRegExp.test(e.target.value)) {
        stains.show();
        $(".qswo-stains-div").show();
        $qswochecked.prop('checked', false);
        $qswoactive.removeClass( "tc-active" );
      } else {
        $(".qswo-stains-div").hide();
      }
    });

    // Check if Hard Maple is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var hMapleRegExp = /^Hard Maple_d$/;
      var rusticHickoryhMapleRegExp = /^Rustic Hickory Twigs and Hard Maple_d$/;

      if (hMapleRegExp.test(e.target.value) || rusticHickoryhMapleRegExp.test(e.target.value)) {
        stains.show();
        $(".h-maple-stains-div").show();
        $hmaplechecked.prop('checked', false);
        $hmapleactive.removeClass( "tc-active" );
      } else {
        $(".h-maple-stains-div").hide();
      }
    });

    // Check if Hickory is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var hickoryRegExp = /^Hickory_d$/;
      var rusticHickoryTwigsHickoryRegExp = /^Rustic Hickory Twigs and Hickory_d$/;

      if (hickoryRegExp.test(e.target.value) || rusticHickoryTwigsHickoryRegExp.test(e.target.value)) {
        stains.show();
        $(".hickory-stains-div").show();
        $hickorychecked.prop('checked', false);
        $hickoryactive.removeClass( "tc-active" );
      } else {
        $(".hickory-stains-div").hide();
      }
    });

    // Check if Walnut is selected or pre-selected
    radio_buttons.on('change', function(e) {
      var walnutRegExp = /^Walnut_d$/;
      var rusticWalnutRegExp = /^Rustic Walnut_d$/;

      if (walnutRegExp.test(e.target.value) || rusticWalnutRegExp.test(e.target.value)) {
        stains.show();
        $(".walnut-stains-div").show();
        $walnutchecked.prop('checked', false);
        $walnutactive.removeClass( "tc-active" );
      } else {
        $(".walnut-stains-div").hide();
      }
    });
});

The HTML code was ripped from the staging site and is therefore very illegible. The best thing to do is drop the JSFiddle link here: JSFiddle link. If anyone has any suggestions on how to cut off some fat, I would very much appreciate it. Or if you have suggestions for reducing the page time (waiting (TTFB)). I tried to delay and / or asynchronize the JS and nothing seems to improve. Again open to suggestions. Thanks a lot!

Edit: Forgot staging site link: Staging site

Event Handling – Is there a default convention for onChange Handlers for Reaction Components?

It seems that some components want to pass an event as the first (or only) argument to a change event, such as For example, (the native input, TextField of the Material UI), and then the programmer accesses the value event.target.valuewhile other components pass the value itself as the first argument (for example, React-Date-Picker).

Here's a codepen that demonstrates this: https://codesandbox.io/s/modern-cache-u8in9.

This is relevant if I use a library like Formik, which has one handleChange Handler expecting to be handed over React.ChangeEvent Objects that are then searched for either an ID or a name and a value.

So when I create a kind of complicated application that uses different components from different sources, it's nice to be able to handle them onChangeEvents in a single way instead of having to write different onChange handlers for different components.

What I thought is that all your onChange handles could be given a signature that looks something like this:

(event?: React.ChangeEvent, value?: U, fieldName?: string) => void;

In this way, someone can either use the component in the formic way (accessing the first argument, or the way the value is passed by accessing the second argument).

Are there concepts or established concepts that deal with this kind of thinking?

PHP – How to test and what kinds of test to write for request handlers that use repository level?

Consider the following class:

class FillTestBySerialHandler
{

    /**
     *
     * @var FillTestBySerialRepository
     */
    private $fillTestBySerialRepository;

    function __construct(FillTestBySerialRepository $fillTestBySerialRepository)
    {
        $this->fillTestBySerialRepository = $fillTestBySerialRepository;
    }

    function handle(): ResponseInterface
    {
        $serial = filter_var($_GET('serial'), FILTER_VALIDATE_INT);

        if (is_int($serial))
            $row = $this->fillTestBySerialRepository->getDataBySerial($serial);
        else
            $row('error') = 'Error: Invalid serial number.';

        return new JsonResponse($row);
    }
}

This is a request handler that receives a serial number, verifies that it is an integer, and sends the command $serial Repository layer to get some data.

The data is returned in an array form, compiled in JSON, and sent back to the caller.

This may be confusing, but my use case is for a Web "test", where "test" is the name for the business logic. Do not confuse the use case "Test" with the component test!

I want to write tests for this class. Which tests should be written if I want to test the class and want to be sure that it is a real problem that needs to be investigated if the tests are interrupted?


I do the following now – I wrote two tests.

I mocked that FillTestBySerialRepository Class with fake data and uses it to test the FillTestBySerialHandler, This means that even if my real database fails or the structure or data changes, my test will NOT fail and still pass because FillTestBySerialRepository is ridiculed.

After writing this test, I thought well of how I know the database is broken. So I wrote another test to test that FillTestBySerialRepository, That is, only mocked data is compared to those retrieved from the real database at the time of the test. If this breaks, I know that the database has changed and is the cause of the error.

But then I thought if I'm doing that, why am I mocking up the database data? Why not just rewrite the first test with real data without mockups.

At this point, I think I need advice on testing my handlers, and I'm here. Please help! What types of tests are normally written for handlers with repository layers? (Handler belongs to the same class as Controller / Action in PHP Framework).

Game Loop – Draw on screen from event handlers

If I have a traditional game loop like this:

while (true) {
    handleEvents(); // Executes any pending event handler
    clearScreen();
    update();
    draw();
}

How can I perform drawing operations in the event handlers? They are deleted. Should I call handleEvents() shortly after clearScreen? Normally, the event query is performed at the top of the game round.

cqrs – Handle the order of domain event handlers

background:

  • We have 2 limited contexts: inventory and sales
  • Application context is the point-of-sale system

scenario:

If a checkout takes place at Sale BC, we would like to reduce the amount in inventory.

problem:

We have 2 dealers in this issue who are interested check-Out or PurchaseCreated Event:

  • The handler from the inventory that reduces the amount of a product
  • The handler for a projection that creates a denormalized view.

In a synchronous environment like PHP, I can choose exactly the right order of event listeners.

I want to know how this is handled in an asynchronous environment?

I would be happy if the answer is not technology-specific, because then at least many of us will benefit from the answer.

Why:

The checkout event contains only (in the simplest form):

  • Date of transaction
  • Product information (ID, name, quantity purchased and current price).

The projection report shows which products are being purchased, what is left and how much they are selling.

The order of the event handler is important for the projection to be correct. The denormalized view contains data that is not in the checkout event. This is the "stock quantity".

When the projection first polls the inventory, it can deduct the inventory amount from the purchased quantity

BUT

If the inventory handler comes first, it would be inaccurate if the inventory amount were deducted from the purchased quantity.

c – Configuration handlers for INI files

and have a nice day! I'm working on a game right now, and I get the configuration in an INI file, and I get information with this library https://github.com/benhoyt/inih. I want to improve the readability / performance of this code. So I do not know much about good practices.

            Include "Project.h"

// typedef struct s_server_conf {
// const char * ip;
// unsigned int port;
//} t_server_conf;

// typedef struct s_db_conf {
// const char * host;
// const char * user;
// const char * passwd;
// const char * db;
// unsigned int port;
//} t_db_conf;

// typedef struct s_conf {
// t_server_conf server;
// t_db_conf conf;
//} t_conf;

static int parse_server (t_conf * conf, const char * name, const char * value)
{
# define MATCH (n) (strcmp (name, n) == 0)

if (MATCH ("ip"))
conf-> server-> ip = strdup (value);
otherwise if (MATCH ("port"))
conf-> server-> port = atoi (value);
otherwise
return (0);
Return (1);
}

static int parse_database (t_conf * conf, const char * name, const char * value)
{
# define MATCH_NAME (n) (strcmp (name, n) == 0)

if (MATCH_NAME ("host"))
conf-> db-> host = (strdup (value));
else if (MATCH_NAME ("user"))
conf-> db-> user = (strdup (value));
else if (MATCH_NAME ("passwd"))
conf-> db-> passwd = (strdup (value));
otherwise
return (0);
Return (1);
}

static int handler (void * conf, const char * section, const char * name, const char * value)
{
# define MATCH_SECTION (s) (strcmp (section, s) == 0)

printf ("name of value,% s, la valeur est% s (name of section% s)  n", name, value, section)
;

if (MATCH_SECTION ("Database"))
return (parse_database ((t_conf *) conf, name, value));
if (MATCH_SECTION ("Server"))
return (parse_server ((t_conf *) conf, name, value));
return (0);
}

void clear_conf (t_conf * conf)
{
if (conf-> db)
free (conf-> db);
if (conf-> server)
free (conf-> server);
free (conf);
}

static t_conf * create_conf (void)
{
t_conf * conf;

if (! (conf = (t_conf *) malloc (sizeof (t_conf))))
return (NULL);
memset (conf, & # 39;  0 & # 39 ;, sizeof (t_conf));
if (! (conf-> db = (t_db_conf *) malloc (sizeof (t_db_conf))))
{
clear_conf (conf);
return (NULL);
}
conf-> db-> port = 3306;
if (! (conf-> server = (t_server_conf *) malloc (sizeof (t_server_conf))))
{
clear_conf (conf);
return (NULL);
}
return (conf);
}
t_conf * get_conf (void)
{
t_conf * conf;

if (! (conf = create_conf ()))
return (NULL);
if (ini_parse ("settings.ini", handler, conf) <0)
{
printf ("Configuration can not be loaded  n");
Exit (1);
}
return (conf);
}

Go API Server – Request handlers become too long

I am developing an API server in Go. My route handlers become excessively long, especially if the answer requires much information.

For the following answer type:

// StateResponse is requested by the client to retrieve the entire beginning
// database status
type StateResponse struct {
StatusCode int `json: 'status'`
User store.User `json:" User "`
registered    []store.Enrol `json:" registered "`
rating  []store.Assessment `json:" Assessment "`
submissions []store.Submission `json:" Submissions "`
}

I have this handler:

func stateHandler (store * store.Store) http.HandlerFunc {
return http.HandlerFunc (func (w http.ResponseWriter, r * http.Request) {
if! request.IsAuthorized (r) {
log.Println ("unauthorized")
unauthorizedHandler (). Serve HTTP (w, r)
return
}
if r.Method! = http.MethodGet {
notFoundHandler (). Serve HTTP (w, r)
return
}
urlParams, ok: = r.URL.Query ()["email"]
        if! ok || len (urlParams)! = 1 {
log.Println ("Invalid e-mail")
badRequestHandler ("invalid e-mail"). Serve HTTP (w, r)
return
}
email: = urlParams[0]
        User, err: = store.GetUserByEmail (email)
if the user == nil || Irr! = Zero {
log.Printf ("User could not be found:% v", error)
notFoundHandler (). Serve HTTP (w, r)
return
}
registered, err: = store.GetEnrolByUser (user.UID)
if enrolled == nil || Irr! = Zero {
log.Printf ("Could not register:% v", error)
notFoundHandler (). Serve HTTP (w, r)
return
}
Estimates, err: = store.GetAssessmentForUser (user.UID)
if ratings == null || Irr! = Zero {
log.Printf ("Valuation could not be found:% v", error)
notFoundHandler (). Serve HTTP (w, r)
return
}
Submissions, err: = store.GetSubmissionsForUser (user.UID)
for submissions == nil || Irr! = Zero {
log.Printf ("Input could not be found:% v", error)
notFoundHandler (). Serve HTTP (w, r)
return
}
// Send answer
resp: = StateResponse {
Status code: 200,
User: * User,
Registered: enrolled,
Rating: Reviews,
Submissions: Submissions,
}
respBytes, err: = json.Marshal (resp)
if wrong! = null {
unauthorizedHandler (). Serve HTTP (w, r)
return
}
w.Write (respBytes)
})
}

I knows that is imperfect. The error handling is repeated. I tried that IrrWriter Technique of Rob Pike's "Error As Values" article, but I could not do it because every database query (business Functions are slightly different in this case.