From f995d3a7c82387bc4d26b27238792e2872f408ab Mon Sep 17 00:00:00 2001 From: Michael Froelich Date: Sat, 10 Jun 2017 22:11:24 +1000 Subject: [PATCH] Example boiler plate code This is a quick start example to of a simple ReactivePage class which searches for a script named main.jsx that takes a single prop. From here, you're best to redefine the GetDatabase function or change it for your database and then replace main.jsx with your UI code. --- Example.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Example.cs diff --git a/Example.cs b/Example.cs new file mode 100644 index 0000000..991ffb3 --- /dev/null +++ b/Example.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json; +using System; +using System.Threading; + +namespace FAP +{ + internal class Example + { + public static void Main(string[] args) + { + ReactivePage.DownloadScripts(); //This line is necessary if you have not downloaded scripts + Index page = new Index(); + Server server = new Server(new[] { page }); + for(;;) Thread.Sleep(-1); + } + } + + /// + /// This is the current basic cookie cutter of a FAP.ReactivePage + /// Name this class the same as the Component name found in whatever script + /// Using "nameof" allows you to rename everything C# side fairly quickly, right click and rename + /// + public class Index : ReactivePage + { + public Index() : base(nameof(Index), null) //This constructor will actually be called by FAP.Server + { //Which isn't great, but all these functions are idempotent + Engine.MinimiseBabelOutput = false; + IncludeScript("main.jsx"); //Since this library is meant for cross platform and so more than one IDE + IncludeCSS("css/main.css"); //Input files cannot be defined within the project or project files + IncludeCSS("css/xbbcode.css"); //It must be defined in the code + //IsSPA = true; //Due to the maturity of the IsSPA functionality, it's now set true as default + get = GetDatabase; //For proficient, safe development, this should be set with a state machine + //(this as Page).get = (a,b) => JsonConvert.SerializeObject(GetDatabase(a,b)); //This also works, but why both? + } + + public object GetDatabase(string a, string b) + { + return (new { name = "not the Computer, but in fact " + a }); + } + } + + +} \ No newline at end of file