Skip to content

Commit

Permalink
Modernize client-server syntax documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed Dec 21, 2023
1 parent 9855e53 commit f9264d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
6 changes: 1 addition & 5 deletions doc/10.x/manual/menu.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

==Client-server programming
===[[clientserver-applications|Eliom applications]]
===[[ppx-syntax|Multi-tier programming]]
===[[clientserver-html|Generating HTML]]
===[[clientserver-communication|Communication]]
===[[clientserver-services|Client-side services]]
Expand All @@ -26,8 +27,3 @@
===[[workflow-compilation|Compilation]]
===[[workflow-configuration|Configuration & running]]
===[[scalability|Scalability]]

==Syntax
===[[ppx-syntax|PPX-based syntax]]
===[[clientserver-language|Camlp4-based syntax]]
===[[ppx-migration|Migration to PPX]]
41 changes: 22 additions & 19 deletions doc/10.x/manual/ppx-syntax.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

The eliom syntax extension allows to write, in one file, both the
client and server part of your application. The extension is
automatically enabled by the {{{eliomc}}} and {{{js_of_eliom}}}
compilers on {{{.eliom}}} and {{{.eliomi}}} files.

For the Camlp4 syntax extension, see
<<a_manual chapter="clientserver-language" | here >>.
automatically enabled by the default build system on
{{{.eliom}}} and {{{.eliomi}}} files.

The extensions presented here are also available with the {{{eliom.}}}
prefix.
Expand All @@ -17,22 +14,24 @@ The location of code execution is specified by section annotations. We
can specify that a declaration is performed on the server, or on the
client:

<<code language="ocaml"|
<<code language="ocaml" class="server"|
let%server s = ...
>>
<<code language="ocaml" class="client"|
let%client c = ...
>>
Or, alternatively:
<<code language="ocaml" class="server"|
[%%server
let s = ...
]

>>
<<code language="ocaml" class="client"|
[%%client
let c = ...
]
>>

Some constructions have a shortcut:

<<code language="ocaml"|
let%client c = ...
>>

Finally, it's also possible to start a section for the rest of the file:

<<code language="ocaml"|
Expand All @@ -44,27 +43,30 @@ In {{{.eliomi}}} files, only the last version is available.

Sections are only available at top level and cannot be nested.

Similarly, you can write for example {{{type%server}}}, {{{module%server}}},
{{{open%server}}}, etc ...

===Shared sections

Shared sections are also available for code that should be on the
client and on the server.

<<code language="ocaml"|
<<code language="ocaml" class="shared"|
let%shared sh = ...
>>

This is equivalent to duplicating the code in a client and a server
section.

==Fragments
==Client fragments

A client-side expression can be included inside a server section, and
the server can thereafter refer to it: an expression placed inside
{{{[%client ... ]}}} will be computed on the client when it receives the
page; but the eventual client-side value of the expression can be
manipulated as a black box on the server.

<<code language="ocaml"|
<<code language="ocaml" class="server"|
let%server x = [%client 1 + 3 ]
>>

Expand All @@ -73,7 +75,8 @@ client, but it’s possible to refer server-side to the future value of
this expression (for example, put it in a list). The value of a client
fragment cannot be accessed on the server.

In this case, {{{x}}} has type {{{int fragment}}}. Eliom can't always
In this case, {{{x}}} has type {{{int Eliom_client_value.t}}}.
Eliom can't always
infer the type of fragments. In this case, you may annotate the type:
{{{[%client ( ... : <type> ) ]}}}.

Expand All @@ -82,8 +85,8 @@ Client fragments cannot be nested.
===Shared fragments

It is also possible to use shared fragments.
<<code language="ocaml"|
let%server x = [%shared ...]
<<code language="ocaml" class="server"|
let%server x = [%shared ...]
>>

It will produce values of type
Expand Down

0 comments on commit f9264d6

Please sign in to comment.