These are chat archives for jdubray/sam

15th
Jun 2017
Jean-Jacques Dubray
@jdubray
Jun 15 2017 00:33
OMG, this is insanity, who in their right mind would want to write something like this?? I demonstrated a couple of years back that node.js XML2JS and simple JavaScript transformations were 90% faster than XSLT (in Java), using the most efficient library possible.
Fred Daoud
@foxdonut
Jun 15 2017 19:19
very interesting :thumbsup:
Johan Alkstål
@johanalkstal
Jun 15 2017 19:35
Very nice
Jean-Jacques Dubray
@jdubray
Jun 15 2017 19:46
Yes, no matter how much a proponent of native apps I was in the 2010-2015 era. The proliferation of form factors and the fact that Web-based technologies deliver a near-native UX, leave no choice today but going Web. I am not disappointed in any way. I believe Web didn't make sense then, as Native no longer makes sense today.
CSS rules!
Marcus Feitoza
@mfeitoza
Jun 15 2017 20:35
There out some native frameworks like Native Script, Tabris, Jasonette, Flutter (Dart lang), bla bla bla.
And Kotlin will support Native too
devin ivy
@devinivy
Jun 15 2017 20:45
@jdubray have you tried polymer yet? google has a whole methodology around making native-feeling web apps. check out PWAs (progressive web apps) and the PRPL pattern.
Jean-Jacques Dubray
@jdubray
Jun 15 2017 20:53
Last time I looked at it I felt it was not a good fit for me. Each time I see a template syntax my eyes shut down. I use ES6 Template Literals and I like it so much that I can't think what people would find in any other approach. I wrote my little XSS/CSRF lib. I use JQuery when needed for DataTables, C3/D3... It works really well.
Johan Alkstål
@johanalkstal
Jun 15 2017 20:55
Trying to think where routing and authorization fits in within the SAM pattern
Things are usually simple until those things need to be added in a project
Jean-Jacques Dubray
@jdubray
Jun 15 2017 20:56
I prefer using social login (gmail, facebook). As I described last time I manage login outside the SAM loop.
Johan Alkstål
@johanalkstal
Jun 15 2017 20:56
Right, I remember. But what's outside? Or when is outside the loop?
Jean-Jacques Dubray
@jdubray
Jun 15 2017 20:56
Routing is not harder, you just need to parse a route into an action which will present the corresponding proposal to the model.
Johan Alkstål
@johanalkstal
Jun 15 2017 20:57
And what if your route is part of your model?
Jean-Jacques Dubray
@jdubray
Jun 15 2017 20:58
@johanalkstal as I said, when you open index.html without being authenticated the model.js file returns an initial model that says {needsLogin: true}, you can detect that without entering the SAM loop and navigate to login.html
Johan Alkstål
@johanalkstal
Jun 15 2017 20:58
Then it's in the loop. Because which route your own is factor for which state representation you create
Jean-Jacques Dubray
@jdubray
Jun 15 2017 20:58
Once you login you'll be redirected to index.html and then model.js will contain all the initial data, from there the SAM loop can start
Even when you don't use social login, you can use the same approach.

And what if your route is part of your model?

Could you elaborate?

There is no value in managing login with SAM
Johan Alkstål
@johanalkstal
Jun 15 2017 21:04
Well does it not make sense to have the route in your model?
It is information that the state needs to be able to decide the proper state representation (view)
Together with possible other properties of the model
In a routable web application, the url is the state driver.
A url change is an event that is handled by an action, creating a proposal
if (model.route.isPrivate && !model.isAuthenticated) {
   // set state representation to the log in view.
  // Possibly make a replace of the browser history
}
As an example
Johan Alkstål
@johanalkstal
Jun 15 2017 21:13
I don't know if it makes sense? I'm just trying to apply the SAM thinking in a more complex context than the usual demo applications.
Come to terms with it
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:14
yes and no, the route is just a call to an action, the result of the action/model needs to match the intent of the route
per say there is no particular need to store the route on the model.
It's really no different than selecting a menu item with some parameters (which you could not do with by clicking on the menu item)
Johan Alkstål
@johanalkstal
Jun 15 2017 21:16
the route is just a call to an action, the result of the action/model needs to match the intent of the route
That was good
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:17
I'd guard the action rather than the model
Johan Alkstål
@johanalkstal
Jun 15 2017 21:18

But, if a route requires an authenticated user, then the Action needs to know 1) is it a private route 2) is the user authorized to go to that route

Then my question becomes, should an Action be able to access the Model?

I believe an action just accepts event data
So passing something from the Model together with an event would break that
?
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:20
The action would just need to know that to be invoked the session must exist, to it would pass a proposal to the model that is either an error (which would render or redirect to a login screen) or the correct proposal if the user has already been authenticated.
No in general you should do everything possible for the action to never have to access the model, this is a strong requirement
Johan Alkstål
@johanalkstal
Jun 15 2017 21:21
Right.
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:21
I am sure there are corner cases where this might be too hard, but I can assure you that each time I bended the semantics of the pattern I regretted it.
You can always call an API from the action to validate the use is authenticated (worst case).
Johan Alkstål
@johanalkstal
Jun 15 2017 21:31

A route event
-> action (knows only about the data in the route event)
-> model (updates the route property)
-> state (can read that model.route.isPrivate && !model.isAuthenticated)
-> stateRepresentation (sign in view)

So far so good I think?

But now, the url also has to be replaced so the address bar doesn't show the protected url, but is updated to the sign in url

Would it be a poor choice if the State updated the browser history?
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:32
Yes, that's an appropriate implementation.
Marcus Feitoza
@mfeitoza
Jun 15 2017 21:33
Hi guys what are your thoughts on this approach: https://jsfiddle.net/hgb234wq/1/
Instead of redraw the VDOM and manage a state for a tooltip.
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:33
No it's a not a poor choice, though I do it in the display function (display of the state representation).
@johanalkstal if you look at the bootstrap blog sample, I manage the browser history and a simple route: /blog/{id}
@mfeitoza Animations will always be tricky with SAM because functional HTML is not applicable to animations
Marcus Feitoza
@mfeitoza
Jun 15 2017 21:36
@johanalkstal I working in an SAM framework and I do example with router, later I post here the result. Because now I'm on Windows and I need pull to GitHub.
Johan Alkstål
@johanalkstal
Jun 15 2017 21:36
@jdubray I'll have a look
@mfeitoza Alright. Cool
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:37
@mfeitoza That being said, I don't have any problem with having a dynamic component coded like the one you did and accepting two properties: {title, tootip}
It's not really part of the application state whether you are displaying the tooltip or not, that's part of the (dynamic) component.
Marcus Feitoza
@mfeitoza
Jun 15 2017 21:42
I think this approach is much simpler than have a VDOM component with internal State to manage.
Jean-Jacques Dubray
@jdubray
Jun 15 2017 21:44
agreed