{"action":"created","issue":{"url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/1","repository_url":"https://api.github.com/repos/fable-compiler/fable-graphics","labels_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/1/comments","events_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/1/events","html_url":"https://github.com/fable-compiler/fable-graphics/issues/1","id":172800395,"number":1,"title":"Pixi: fail to use renderer","user":{"login":"whitetigle","id":883207,"avatar_url":"https://avatars.githubusercontent.com/u/883207?v=3","gravatar_id":"","url":"https://api.github.com/users/whitetigle","html_url":"https://github.com/whitetigle","followers_url":"https://api.github.com/users/whitetigle/followers","following_url":"https://api.github.com/users/whitetigle/following{/other_user}","gists_url":"https://api.github.com/users/whitetigle/gists{/gist_id}","starred_url":"https://api.github.com/users/whitetigle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitetigle/subscriptions","organizations_url":"https://api.github.com/users/whitetigle/orgs","repos_url":"https://api.github.com/users/whitetigle/repos","events_url":"https://api.github.com/users/whitetigle/events{/privacy}","received_events_url":"https://api.github.com/users/whitetigle/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-23T20:36:49Z","updated_at":"2016-08-24T22:33:03Z","closed_at":"2016-08-24T05:55:52Z","body":"Hi!\r\nI am trying to setup a very simple Pixi project. However I fail right at the start with a compilation error.\r\nSince I am new to both Fable & F# there may be things I do wrong.  Or maybe I did not understand the **Erase attribute** sample in the doc since **Globals.autodetectRenderer** returns a **U2\\<WebGLRenderer, CanvasRenderer\\>**\r\n\r\nAnyway here is my code : \r\n\r\n```\r\nopen System\r\nopen Fable.Core\r\nopen Fable.Core.JsInterop\r\nopen Fable.Import.PIXI\r\nopen Fable.Import.Browser\r\n\r\nlet currentRenderer =\r\n  let renderer = Globals.autoDetectRenderer( 800., 600.  )\r\n  match renderer with\r\n    | U2.Case1 webgl -> webgl :> SystemRenderer\r\n    | U2.Case2 canvas -> canvas :> SystemRenderer\r\n\r\ndocument.body.appendChild( currentRenderer.view )\r\n```\r\n\r\nWhen I compile it says : \r\n\r\n> fable-compiler 0.5.8: Start compilation...\r\nERROR: Unsupported type test: GenericParam \"b\" (L27,8-L27,16) \r\n\r\nwhich corresponds to my renderer value\r\n\r\n> match **renderer** with\r\n\r\nI use fable-core 0.5.5. \r\nI have tried other ways but I can't get past this error. \r\nThanks for your kind help!"},"comment":{"url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/comments/242229292","html_url":"https://github.com/fable-compiler/fable-graphics/issues/1#issuecomment-242229292","issue_url":"https://api.github.com/repos/fable-compiler/fable-graphics/issues/1","id":242229292,"user":{"login":"alfonsogarciacaro","id":8275461,"avatar_url":"https://avatars.githubusercontent.com/u/8275461?v=3","gravatar_id":"","url":"https://api.github.com/users/alfonsogarciacaro","html_url":"https://github.com/alfonsogarciacaro","followers_url":"https://api.github.com/users/alfonsogarciacaro/followers","following_url":"https://api.github.com/users/alfonsogarciacaro/following{/other_user}","gists_url":"https://api.github.com/users/alfonsogarciacaro/gists{/gist_id}","starred_url":"https://api.github.com/users/alfonsogarciacaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfonsogarciacaro/subscriptions","organizations_url":"https://api.github.com/users/alfonsogarciacaro/orgs","repos_url":"https://api.github.com/users/alfonsogarciacaro/repos","events_url":"https://api.github.com/users/alfonsogarciacaro/events{/privacy}","received_events_url":"https://api.github.com/users/alfonsogarciacaro/received_events","type":"User","site_admin":false},"created_at":"2016-08-24T22:33:03Z","updated_at":"2016-08-24T22:33:03Z","body":"Sorry for the late reply. This is an awesome job! :clap: It'd be fantastic to add the samples to Fable's website 😄  I'll try to answer your questions now:\r\n\r\n> Regarding the Erased unions, I was following the example from https://fable-compiler.github.io/docs/interacting.html page:\r\n\r\nThanks for pointing this out! This was actually a bug in Fable, it should be possible to type test erased union types (e.g. `match x with U2<string,int>.Case1 s -> ...` will translate to `typeof x === \"string\" ? ...`). It will be fixed in the next release :+1: However, in your specific case I think unboxing is fine. Of course `unbox` is less safe than a type test, but there both branches were casting to `SystemRenderer` so it should be fine.\r\n\r\n> If I encounter other problems may I ping you from time to time? If so is is better to use gitter for that or submit an issue?\r\n\r\nOf course you can ping me :) Gitter is good for short questions and there're also other people listening there so you may get an answer faster there. But GH issues are also good to record answers so other people can easily find the info. Whatever is more convenient for you will work.\r\n\r\n> Is there a way to define default values instead or make options becomes REALLY optional (create the object in JS without the field)\r\n\r\nYeah, this is an issue as unfortunately there's no way in F# to have optional members 😕 But as most of the times in JS this is done for option objects (as in this case) we have an alternate way: [key value lists](https://fable-compiler.github.io/docs/interacting.html#KeyValueList-attribute). Unfortunately, `ts2fable` won't create this type of definitions but it's easy to do it yourself:\r\n\r\n```fsharp\r\n[<KeyValueList>]\r\ntype RendererOptions =\r\n    | View of HTMLCanvasElement\r\n    | Transparent of bool\r\n    | Antialias of bool\r\n    | AutoResize of bool\r\n    | Resolution of float\r\n    | ClearBeforeRendering of bool\r\n    | PreserveDrawingBuffer of bool\r\n    | ForceFXAA of bool\r\n    | RoundPixels of bool\r\n    | BackgroundColor of float\r\n```\r\n\r\nNow you can only specify the options you need:\r\n\r\n```fsharp\r\nlet currentRenderer =\r\n    let options = [\r\n        Antialias true\r\n        Resolution 1.\r\n        BackgroundColor (float 0x000000)\r\n    ]\r\n    Globals.autoDetectRenderer( 800., 600., options )\r\n    |> unbox<SystemRenderer> \r\n```\r\n\r\n> However since there are a lot of samples, I wonder how to define a single build file to generate the .js files from all the .fsx files located in a folder. I have not yet found a way to do this easily using fableconfig.json (any hint in the doc?) Do I need to use a .fsproj file?\r\n\r\nIt depends if you consider all samples to be part of the same project (in this case we may think of a project as one HTML page). `fableconfig.json` doesn't support multiple projects but if you want to compile all samples at once in the same project, you can use `.fsproj` or just another script that loads the others with the `#load` directive ([example](https://github.com/fable-compiler/fable-electron/blob/master/samples/helloworld/src/files.fsx)). For the websites samples we usually use a script file with a tutorial and a small configuration to automatically set up the web page. See this issue for an explanation of the process: https://github.com/fable-compiler/Fable/issues/162\r\n\r\nI hope this helps! Please tell me if you have more questions and thanks a lot for your contribution!"}}
{"actor":{"display_login":"alfonsogarciacaro"}}