[JSMODELS-4] Provide samples of how to use JS models Created: 16/May/17  Updated: 18/Jul/17  Resolved: 14/Jul/17

Status: Closed
Project: Magnolia Javascript Models
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Neutral
Reporter: Christopher Zimmermann Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to JSMODELS-6 Bad type when passing a returned js o... Closed
Template:
Acceptance criteria:
Empty
Task DoR:
Empty
Documentation update required:
Yes
Date of First Response:
Epic Link: LD: Fundamental features
Sprint: Kromeriz 101, Kromeriz 103, Kromeriz 104, Kromeriz 105
Story Points: 8

 Description   

We should provide samples of how to work with Magnolia FTL data-structures in JS models.
They can be tricky to work with because one needs to know the data structure that is passed in to a JS function from the FTL. Samples will help with this and give developers a good starting point.

Samples can also help to illustrate possible use cases for the feature.
(Initiative validation: https://wiki.magnolia-cms.com/display/PMTEAM/Template+model+LDV)

Use cases to demonstrate:

  • Keep templates simpler by moving logic into model.
  • Processing the post of a frontend form.
  • Communicating with Magnolia internals.
  • Making a REST GET or POST

Probably the samples can best be delivered as one light module.

I created a few samples while testing the feature that may be useful as a starting point:
https://git.magnolia-cms.com/users/czimmermann/repos/js-model-samples/browse/light-modules/js-model-samples

There are some notes here: https://wiki.magnolia-cms.com/display/PMTEAM/LD+Testing+-+JS+Models

The samples should be documented with a README in the project, and should also be mentioned in Magnolia docs.



 Comments   
Comment by Jaroslav Simak [ 17/May/17 ]

There's still some ugly bug that if you pass return javascript object (array, json) to the model, it's type gets changed and it does not behave as it should if you pass it again to another model function.

As i can see it's described in the Some learnings section of the https://wiki.magnolia-cms.com/display/PMTEAM/LD+Testing+-+JS+Models page.

It's something related to freemarker template object wrapping, so fixing it might be a little bit tricky.

Comment by Christopher Zimmermann [ 09/Jun/17 ]

Yes I agree with: "Keep templates simpler by moving logic into model - this could be taken from samples you wrote earlier, wdyt?" can you add them? I would like to get them reviewed by you and some other members of the team with JS & FTL experience - such as fgrilli

Comment by Christopher Zimmermann [ 09/Jun/17 ]

It feels a bit cluttered to have "libs" and "formProcessors" at the root, but I see that they do not make sense in "webresources" for example. (formProcessors is not a registry right?)
What about a root dir called "js" and those dirs go in it?

Comment by Christopher Zimmermann [ 09/Jun/17 ]

Overall- what you have so far in the above repo looks great.

Comment by Jaroslav Simak [ 11/Jul/17 ]

https://git.magnolia-cms.com/users/jsimak/repos/javascript-model-samples/browse

Comment by Evzen Fochr [ 13/Jul/17 ]

piQA done on clone from jsimak repo.

Generated at Mon Feb 12 05:58:42 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.