12

I'm having real trouble trying to get started with FunScript, I really love the idea of F# -> Javascript but constantly frustrated by the amount information/documentation of how to work with such beautiful-looking technologies.

Here's the problem:

The FunScript Project (No Hosting) template cannot be installed because: "You need Nuget Installed", says VS when I try to download it. // Dah, I do have Nuget and just updated it to latest release. I'm using VS2013 Ultimate.

I did the following:

I created a new FSharp Library Project and then I ran the Package Maneger command for getting the needed FunScript Libs:

PM> Install-Package FunScript

that worked nice but then . . . When I look at a FunScript example I see the open FunScript.TypeScript in the program which currently does not exist when I type that as it says TypeScript is not defines, and looking at the examples FunScript.TypeScript gives the ability to use jQuery and interact with the DOM. so without it i can't do anything here

I did notice the 3rd-party libs on Nuget for FunScript, the:

FuncScript.TypeScript.Bindings.(lib|jquery)

but i can't reference those in an "open [namespace]" statement.

and at last, there must be a "do Runtime components ..." something at the end of the program. this also is 'not defined'

Do you guys have a complete FunScript example that I can start with? (I have already searched the web alot, the programs i saw didn't work with me)

Zaid Ajaj
  • 680
  • 8
  • 16
  • Have you tried looking at the github repo for funscript? https://github.com/ZachBray/FunScript/tree/master/Examples – N_A Nov 24 '13 at 06:18
  • This problem shows up when loading the FunScript Examples fresh off github into Xamarin Studio as of today. What's the official solution? – Alexy Feb 17 '14 at 19:07

3 Answers3

14

Sorry, the project is still a bit thin on documentation. We will try to improve this soon.

I have now updated the FunScript Visual Studio Project Template to remove the NuGet Package Manager dependency. From v1.1.0.15 It should work on Visual Studio 2013. Note: you may need to build twice to restore the NuGet packages correctly.

You only get the basic F# to JS compiler (and some FSharp.Data type provider mappings) in the main NuGet package. If you want to access JavaScript through TypeScript bindings you must add references to those "Bindings" packages you mentioned.

The names of these packages don't actually reflect any namespace within the assemblies. Currently, they import types into the global namespace (i.e., they should just become available in intellisense without opening any namespaces). Unless the TypeScript contains modules, in which case the functions and types are mapped to the corresponding .NET namespaces.

E.g., Globals.alert(message) should type-check after you have added the FunScript.TypeScript.Binding.lib NuGet package.

Please note, we may move these definitions all up into the FunScript.TypeScript namespace in future to avoid polluting the global namespace.

The do Runtime.Run(components) call in the examples is actually just a helper method. We should probably remove this from the examples, as it confuses a lot of people. The only method call you really need is Compiler.Compile(<@ main() @>, noReturn = true), which compiles the quotation and returns a string of JavaScript. It is then up to the user what they do with this JavaScript (e.g., put it in a hosted page).

I'll be adding more documentation around using FunScript when I release another project called HashBang, which makes use of FunScript to build crawlable-dynamic-websites. This will include step-by-step tutorials for building and deploying with HashBang/FunScript.

ZachBray
  • 353
  • 2
  • 7
  • Thanks for the answer, I will go try the template now – Zaid Ajaj Nov 24 '13 at 12:19
  • 1
    @ZackBray I have just tried the project, Like you said, I had to build twice, at this point, there are no error (nor warnings) but when running the progeam, I get a "TypeInitializationException" that was thrown from "FunScript.Data.Components",info -> "The type initializer for '.$FunScript.Data.Components' threw an exception." is this actually a stable release or should I wait for HashBang ? – Zaid Ajaj Nov 24 '13 at 12:39
  • It is certainly stable in VS 2012 with F# v3.0. I haven't tested with VS 2013 and F# v3.1 yet. I haven't heard of any other issues around this yet though. Looks like the issue is coming from the FSharp.Data type provider mappings. You could try removing that assembly for now and avoiding the Apiary/WorldBank type providers. Otherwise, yes wait a while until we are using VS 2013. – ZachBray Nov 25 '13 at 22:11
4

I had a smooth entry ...

Used MS Visual Studio 2013 (professional), with the vanilla "FunScript - Not Hosted" project template (by Zach Bary), which can be found through the online project search.

Then add relevant FunScript binding packages (through NuGet). I added for some of my solutions: FunScript.TypeScript.Binding.jquerymobile and FunScript.TypeScript.Binding.phonegap

You can see several of my examples on GiHub (https://github.com/ZachBray/FunScript/tree/master/src/samples/EasyGettingStarted). All you need to do is replace the Program.fs from the default project (FunScript - Not Hosted). And add the rest of the files. I am using as a base some of Zach Bray code. See the README file on the link above.

Should be a 5-10 minutes experience for you if you have MS VS 2013 installed. I am in the process of submitting more examples. I recommend Funscript.

TalBeno
  • 279
  • 2
  • 13
0

As per Zach's advice above, I created a working (at least time of writing) example project for OSX and Xamarin Studio:

https://github.com/mfrawley/Funny

I found the install process absolutely unintuitive but now that it's working and seeing the plethora of NuGet packages available, I'm getting pretty excited to see how this thing develops.

Mark
  • 604
  • 5
  • 8