Skip to content

Commit

Permalink
Example boiler plate code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MichaelFroelich authored Jun 10, 2017
1 parent 3ed9cbb commit f995d3a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Example.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

/// <summary>
/// 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
/// </summary>
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 });
}
}


}

0 comments on commit f995d3a

Please sign in to comment.