These are chat archives for jdubray/sam

27th
Feb 2016
José Pedro Dias
@JosePedroDias
Feb 27 2016 00:41
did it :)
publishing
José Pedro Dias
@JosePedroDias
Feb 27 2016 00:59
here it is
Jean-Jacques Dubray
@jdubray
Feb 27 2016 01:37
thank you !
José Pedro Dias
@JosePedroDias
Feb 27 2016 01:38
you're welcome. I'll study the idea a bit more. I'll surely disseminate it if I get to adopt it :)
Jean-Jacques Dubray
@jdubray
Feb 27 2016 01:38
thank you!
Troy
@troyji
Feb 27 2016 05:51
Hello
Jean-Jacques Dubray
@jdubray
Feb 27 2016 05:59
Hi, welcome
Troy
@troyji
Feb 27 2016 06:00
There is a composition diagram that shows a SAM implementation on both the client and the server. The diagram suggests that the view would call an action on the server. This only seems applicable for things like redirects or form posts. In the case of an AJAX based communication scheme, it seems that view should call into the client-side action, which would in turn invoke the an action server-side through AJAX and await the response from the server-side state. Is this the type of flow you would invision for this case, or do you have an alternative technique?
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:04
@troyji There are two scenarios:
  • the client instance is a wizard which completes when the user triggers the server side action.
  • the client instance continuously communicate with the server, the client instance is used to keep state on the client for performance reason
Now assuming an AJAX call on the client, it could look like this:
function myServerSideAction(data, present) {

    var options = {
      url: 'http://www.company.com/actions/mySSA',
      headers: {
        'accept': 'application/json'
      }
    };

    request(options, function (error, response, body) {
       if (!error && response.statusCode == 200) {

               data.interestingStuff = body.stuff ;
               present(data) ;

       }
     });
}
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:09
That's some node.js code, but the JQuery equivalent would be pretty close

Similarly, the model of the client instance could invoke CRUD operations to the persistence layer.

Alternatively, the mySSA action could update the model on the server, while looping back to the view via the client instance.

I believe the pattern is very flexible, say compared to Redux.
Troy
@troyji
Feb 27 2016 06:13
So you would feel comfortable calling the service layer from either place: action or model, is that correct?
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:13
That's because actions are not anemic and the model is "stateful", SAM does not have to do the React danse where we first have to create an entire copy of the state and then update the store with that new copy. In a client/server scenario, it would mean that if the update has to happen on the server, we have to ship back the entire copy of the state.
Just with one caveat, Actions do not mutate the mode, they present data to the model
so the exact same data set could be presented to the server side model or the client side model
when the model calls an API, it is exclusively to persist its properties
Troy
@troyji
Feb 27 2016 06:15
Very good.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:15
That's the problem with Redux and React in general, there seem to never be a good time to call an API, at least that's how I feel.
I created last year the "ReaCall" pattern to help with that
but that's just a hack
Troy
@troyji
Feb 27 2016 06:16
I am intrigued by SAM, but there is one issue that I have with it that I would like to find a way around.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:16
Yes, that was my main goal when I started, I wanted to find a better way to articulate API calls
Please let me know
Troy
@troyji
Feb 27 2016 06:20
I have been developing using the MVVM pattern client-side. I am convinced that creating UI via declarative binding is superior to imperative binding. Specifically, I use knockout.js which binds the view to the view model via html data-bind attributes.
I cannot bring myself to wrap my html in functions. A couple of reasons: it does not feel natural, tooling support is minimal (e.g. intellisense, syntax highlighting), etc.
I would like to find an approach to incorporate a more natural declarative style view with the functional SAM approach.
Troy
@troyji
Feb 27 2016 06:25
The best idea I have come up with is to decompose the HTML into templates that are consumed by the state.view. Likely the state.view would then follow up with applying a decomposed view model to the decomposed HTML as needed through the binding library of choice.
This approach seems OK, but perhaps not optimal. Do you have any ideas for this?
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:27
There is no reason not to use template other than I prefer the imperative binding
It's clear that this is only a question of preference
We tried yesterday with Angular2 templates and there seem to be no problem
it may not be true with other templating technologies
SAM works also in a Request/Response (aka interactive Way), but again I prefer thinking of it as a "reactive loop" and V = f(M)
The way to run it in an interactive way is to to consider, just like in MVC that the View talks to a controller and the controller's logic implements A-M-S in one operation
Troy
@troyji
Feb 27 2016 06:30
I think my biggest concern with templates is that it could be difficult to manage the growing number of disconnected templates (the same issue exists with the imperative approach). This is as compared to a fully composed template where you hide/show areas as the state changes (in this setup it is always clear where to find the UI piece you are looking for).
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:33
Too hard to create a sequence diagram, but I guess you see my point
Troy
@troyji
Feb 27 2016 06:35
Yes, I see your point ;-)
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:37
All I wanted to achieve with raw javascript functions was to:
a) enable any dev to build decent Web apps / Web sites (without front-end skills like me and who don't have the time to learn React / Angular)
b) perhaps reset some of these frameworks, like React, that seem to have completely lost their mind. They are baking a level of complexity that no longer make sense, and seems to be totally unnecessary
Troy
@troyji
Feb 27 2016 06:38
I think I would prefer to stick with the reactive approach - I just need to find a nice solution for my view implementation. I presented SAM to my development group and we discussed it's implications for our large scale enterprise web applications. The 2 questions that I posed today were the two main sticking points that we were unsure about (which layer consumes AJAX and how might we preserve declarative binding). Everyone was intrigued by SAM, for certain.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:42
thank you for your feedback, happy to answer any question you have. I just added the composition pattern we talked about (client/server side models kept in sync by presenting the same dataset to both model.
Troy
@troyji
Feb 27 2016 06:42
Have you given a name to the data that the action presents to the model? My best description of it was to associate it with the command pattern.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:46
sure, I don't want to be too prescriptive because people might choose to implement it with actions, events (pub/sub), ... again, my preference is dataset, but that is not essential to the structure of the pattern.
Troy
@troyji
Feb 27 2016 06:46
I feel that I could have benefited from suggestions on how to best model the data. It is tempting to just mimick the model and present it for merging - which completely defeats the purpose.
But perhaps these types of issues will become clear once I build out my own samples (get my hands dirty).
Jean-Jacques Dubray
@jdubray
Feb 27 2016 06:50
It's not going to be really clean either way. There's been a lot of good work with merging datasets with a model, so my best bet is that it will prove to be superior, but happy to be proven wrong.
Actions however provide an important decoupling between the View and the Model, if for nothing else the view no longer has to bind to the structure of the model (or vice versa)
I like the work that Mike McNeil has done recently on functions/actions, I tried to connect with him, but like Dan, he seems very busy.
Troy
@troyji
Feb 27 2016 06:53
Are you suggesting that mimicking the model may, in fact, be the best design for data and the action simply serves to transform the view's intent into a model-like dataset?
Jean-Jacques Dubray
@jdubray
Feb 27 2016 07:02
well, that's my intuition. I can't really prove it, nor can be sure that it works in every situation
Troy
@troyji
Feb 27 2016 07:03
Under 'Code Samples', you have mislabeled the item-list sample as 'Rocket Launcher sample' (2nd to last link).
Jean-Jacques Dubray
@jdubray
Feb 27 2016 07:03
The intent of TLA+ (and Paxos protocol) is to "propose" values to the model, so intuitively, I have tried to follow these formalisms
thank you, corrected
Troy
@troyji
Feb 27 2016 07:05
Interesting. I have been thinking of it more like "I propose that you make change x and change y to item 3 of list a" as apposed to "I propose you replace list a with list b".
Jean-Jacques Dubray
@jdubray
Feb 27 2016 07:07
That's one big limitation of the dataset is that you cannot always convey intent from the dataset itself, you need an action/intent label
In general you are close enough to the model that the intent is clear, but not always, that's why I am prudent
Troy
@troyji
Feb 27 2016 07:11
Thanks for the discussion. I will keep an eye on SAM and look forward to experimenting further.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 07:11
thank you!
Troy
@troyji
Feb 27 2016 08:31
@jdubray, here is the SAM rocket launcher sample using HTML templates with knockout.js data binding.
Jean-Jacques Dubray
@jdubray
Feb 27 2016 08:42
Yes, that works well, the templates. I was also wondering how you would mount the templates based on the current state of the system, but that seems like a good solution:
// State representation of the ready state
view.ready = function(model) {
    return document.getElementById("ready_template").text;
}
If it's ok, I'll add it to the list of sample code
Jean-Jacques Dubray
@jdubray
Feb 27 2016 08:52
great news, the Getting Started Guide got mounted at http://sam.js.org
brusand
@brusand
Feb 27 2016 09:56
Super jj so many thx
Troy
@troyji
Feb 27 2016 15:35
@jdubray, sure, feel free to use it. I will note that there are probably a few refinements that could/should be made to get this production ready.
Troy
@troyji
Feb 27 2016 15:44
This message was deleted