Commit 2b9d20e4 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Adding new application framework

parent b96f9fac2bb1
let renderLoading =
(
_resources: Framework.StringMap.t(Framework.resource),
_state: Framework.appStateLoaded,
) =>
<div> (ReasonReact.string("Loading")) </div>;
let renderRoot =
(
_resources: Framework.StringMap.t(Framework.resource),
_state: Framework.appStateLoaded,
) =>
<div> (ReasonReact.string("Root")) </div>;
let renderCollection =
(
_resources: Framework.StringMap.t(Framework.resource),
_state: Framework.appStateLoaded,
) =>
<div> (ReasonReact.string("Collection")) </div>;
let renderEntity =
(
_resources: Framework.StringMap.t(Framework.resource),
_state: Framework.appStateLoaded,
) =>
<div> (ReasonReact.string("Entity")) </div>;
let defaultRegistry =
Framework.Create.registry([
Framework.Create.view(
"::defaults::Root",
"Default root view",
Framework.RootView,
0,
renderRoot,
),
Framework.Create.view(
"::defaults::Collection",
"Default collection view",
Framework.CollectionView(None),
0,
renderCollection,
),
Framework.Create.view(
"::defaults::Entity",
"Default entity view",
Framework.EntityView(None),
0,
renderEntity,
),
]);
\ No newline at end of file
......@@ -62,8 +62,8 @@ type resource = {
(* Type of a rendering function *)
type renderer =
(resource list)
-> appState
resource StringMap.t
-> appStateLoaded
-> ReasonReact.reactElement
(* The definition of a view *)
......@@ -267,20 +267,36 @@ let reduce action state = match action with
| LoadingFailed(requestedData) -> reduce_on_failed state requestedData
| LoadingCompleted(fetchedData) -> reduce_on_loaded state fetchedData
(* When some data has been loaded *)
let on_loaded_data (self: (_, _, _) ReasonReact.self) fetchedData = begin
self.send(LoadingCompleted(fetchedData));
match fetchedData with
| FetchedSchema(target, schema) -> begin
match schema with
| Hypermedia.ArrayType(_)
| Hypermedia.ObjectType(_) -> begin
self.send(Request(RequestedData(target)));
()
end
| _ -> ()
end
| _ -> ()
end
(* Launched a request for some data *)
let do_fetch requestedData (self: (_, _, _) ReasonReact.self) = match requestedData with
| RequestedData(target) -> begin
(Hypermedia.Fetch.fetch_data
target
(fun () -> self.send(LoadingFailed(requestedData)))
(fun data -> self.send(LoadingCompleted(FetchedData(target, data)))));
(fun data -> (on_loaded_data self (FetchedData(target, data)))));
self.send(LaunchedRequest(requestedData))
end
| RequestedSchema(target) -> begin
(Hypermedia.Fetch.fetch_shema
target
(fun () -> self.send(LoadingFailed(requestedData)))
(fun schema -> self.send(LoadingCompleted(FetchedSchema(target, schema)))));
(fun schema -> (on_loaded_data self (FetchedSchema(target, schema)))));
self.send(LaunchedRequest(requestedData))
end
| _ -> self.send(LaunchedRequest(requestedData))
......@@ -304,19 +320,20 @@ let on_updated (oldNewSelf: (_, _, _) ReasonReact.oldNewSelf) =
let follow_link link =
ReasonReact.Router.push link
(* Module for the default views *)
(*
module Defaults = struct
let defaultViewRoot = {
module Create = struct
let view location name kind priority renderer = {
specification = {
location = "::defaults::root";
name = "Default root view";
kind = RootView;
priority = 0;
};
renderer = Defaults_rendering.renderRoot;
location = location;
name = name;
kind = kind;
priority = priority;
};
renderer = renderer;
}
end
*)
\ No newline at end of file
let registry (views: view list) =
List.fold_left
(fun registry view -> register_view registry view)
{specifications=StringMap.empty; definitions=StringMap.empty;}
views
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment