vendredi 23 juin 2017

EF an cqrs: editing and entity while both keeping separation of layers and of query and command

I am changing a crud nTier web app(MVC) to a cqrs implementation (this is my first time doing this) and i'm now splitting what was the business layer. I'm having trouble rewriting some commands that edit entities this is due to the fact that I would have to run a query to get the entity in order Edit it. I think the correct thing to do would this would be to get the controller to run a query and then pass the entity down but this seems to brake the separation between tiers as it would mean the presentation layer would know about the Data access. What do I do here, is there a way in EF to edit an entity using a new version of the model used to create the entity. If that is not possible how can I do this without breaking separation of concerns or cqrs.

Some options i have considered are

  • Pulling my models out into a common library

  • Doing a query in the command stack but still returning nothing

Apple Watch and iOS targets: Is this a good idea to avoid repetitive code?

I use to have model classes in my apple watch target that is used to store data and modify string data. However, most of the code in the models that I was using could be found in my iPhone app target. So what I did was deleted all the models in my apple watch target and instead using my iPhone models to store and modify string data.

This seems like the correct approach because not only is there less classes, but I only have to make changes once instead of twice if there is any features or changes needed. I'm not use to having more than one target in a project and just want to be on the safe side.

Flux with alt - cannot dispatch in the middle of dispatch.- wrong design pattern?

I build an app with pure React. It's primary page shows multiple movies (user added). Users can vote and comment on every movie listed. I have a MovieCard component, which is responsible for single movie. Then in Home I render an array of MovieCard components. Next decided to implement a call to foreign movie database API, to get relevant movie information. I works fine. Then I decided to refactor it in Flux pattern, using Alt and following the guidelines of this tutorial. Everything worked well, until I got the the MovieCard. In there, inside componentDidMount I call the action, which sends ajax and retrieves a poster url. And I got this error.

First, I read this topic. The author of the answer claimed that having each component handles its actions is bad design pattern and is what cause the error. His solution would be to handle ALL actions and stores from the top-most component (App) and pass down as props. My thoughts:

  • I don't like it, because it means passing down a LOT of data and callbacks and my App.js is going to be overly long and ugly and clouded. Lastly I don't know how this is the "React way", where each component is standalone and can work on it's own, out of App context.
  • I don't see how it fixes the problem. I want my MovieCard to fire action to get data inside componentDidMount. So even if App is handling the actions, when multiple movies are shown, then multiple actions will be fired, again.

Then I read this topic. I don't think I am using actions wrong. Here is my action:

getMoviePoster(movieName) {
    TMDB.getMoviePoster(movieName)
        .then(data => this.getMoviePosterSuccess(data))
        .catch(err => this.getMoviePosterFail(err));

    return true;
}

I followed the pattern, showed in the guide I linked above. There were no errors there.

I read through some other topics, there was something about waitFor token, but I couldn't make much of it. Can anyone please shed some light on the issue, because I am in sort of a hurry. I need it done by Tuesday, and I may have a major refactoring on my hands now... I really don't understand what is the problem here. I know Flux is unidirectional, but I thought that's for one component. I'm not guru here, but I can't really see unidirectional flow for the entire application (even this small). I don't see what's the problem of having multiple instances of the same component doing stuff simultaneously.

Using singleton to initialize varibles

I'm learning design patterns, in one of the tasks in the book i have 2 variables that are global. data and collected. I want to initialize them on start similar to code below. data is input field and collected is function. Task is to do it with singleton, is that even possible?. All examples on the net are just functions and single instance?

"use strict";
var data;
var collected = [];

    window.onload = function() {
        data = document.querySelector("#data");
        colected = function() {
            console.log(data);
        }
    }

What it's the canonical way of interfacing DB's id with HTML id?

So I'm writing a simple way app. It has SQLite as the RDBMS, Python's bottle framework as server and rest is HTML, CSS and JavaScript.

Now, we all know that HTML tags cannot have id(s) starting with a numeral. And using text/string as primary key in database would be hell.

Right now I'm converting DB id to string and adding an _ before it so it renders correctly in HTML. And doing the reverse when DB needs to be updated. But my code doesn't look beautiful.

So what's the standard accepted way of making these two talk? Where should I implement the translator, in Python or in JavaScript? What background does this problem have in conventional computer science?

jeudi 22 juin 2017

Same computational flow, but different functionalities

Recently I wrote a small piece of code for my project need and the code works fine...

Below code is a generalized version....

if (Utils.nullOrEmpty(string1))
        {
            Config config = getConfig();

            if (config != null)
            {
                doX();
            }
        }
        else
        {
            doY();
        }

        if (Utils.nullOrEmpty(string2))
        {
            Config config = getConfig();

            if (config != null)
            {
                doA();
            }
        }
        else
        {
            doB();
        }

I am not convinced the way it is written and I feel there is a scope for improvement to make it better........

Please give me some suggestions to make it better... Is there a scope to use lambdas ??.........

How to adapt to changes in API

I have a large project that depends on certain library. One of this library classes exposed the following methods:

public void until(final Predicate<T> isTrue)
public <V> V until(Function<? super T, V> isTrue) {

where Predicate and Function are:

com.google.common.base.Predicate<T>
com.google.common.base.Function<? super T, V>

In the last version of that library the above has been changed and was refactored by deprecating(removing) the public void until(final Predicate<T> isTrue) method and amending the second method as follows:

public <V> V until(Function<? super T, V> isTrue)

where Function is now java.util.function.Function<? super T, V>.

As far as I understand the above changes has been done to fully support Java 8 features and specifically lambda expressions.

Now to my question. While I can transform all calls to until that used the deprecated version of this method to the new structure but I am afraid there are too many places where this method is called. Is there a way I can keep using the old (deprecated) method by maybe re-declaring it elsewhere myself or any something of a kind? Any alternative ways to solve this problem are happily accepted.