Skip to content

investigate Custom Object Formatters in Chrome Dev Tools #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bobzhang opened this issue Mar 7, 2016 · 4 comments
Closed

investigate Custom Object Formatters in Chrome Dev Tools #151

bobzhang opened this issue Mar 7, 2016 · 4 comments

Comments

@bobzhang
Copy link
Member

bobzhang commented Mar 7, 2016

https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#heading=h.xuvxhsd2bp05

@bobzhang
Copy link
Member Author

bobzhang commented Mar 7, 2016

note that we have almost all the meta data for a custom formatter (even the field names of submodules)

@bobzhang bobzhang added the ideas label Mar 11, 2016
@bobzhang bobzhang added this to the beta-release milestone Mar 11, 2016
@bobzhang bobzhang modified the milestones: future-, beta-release May 23, 2016
@bobzhang bobzhang removed this from the after-4.04 milestone May 25, 2017
@bobzhang
Copy link
Member Author

Below is a simple snippet to recognize ocaml exception and print it in a reasonable way

window.devtoolsFormatters = []
window.devtoolsFormatters.push({
    header : function (x){
        if (x.tag === 248){
            return ["span", {"style": "background-color: #fcc"}, "exn/open variant", x[0]];
        }else {
            return null
        }
    },
    hasBody : function(x){
        return false 
    },
    body: function(x){
        return null
    }
})

@jaredly
Copy link
Contributor

jaredly commented Aug 14, 2017

so we could wipe out custom object formatters, pretty printing, and json conversion all in the same manner, by generating a x__bs_to_json function for each type x declaration.

for example

type person = {name: string, age: int, friends: list string, airplane: PlaneLibrary.plane}
/* generated function: */
let person__magic__to_json person => {
  { /* I'm pretending that a js object is a Js.Json.Object */
     "name": string__bs_to_json person.name,
     "age": int__bs_to_json person.age,
     /* note a type w/ a parameter takes as the first function "a => Js.Json.t" */
     "friends": list__bs_to_json string__bs_to_json person.friends,
     "airplane": PlaneLibrary.plane__bs_to_json person.airplane,
  }
}

I use json as an example, but we could just as easily produce a js object like
{$bs_type: 'record', $bs_name: 'person', $bs_attributes: {name: 'julia', ...}} for chrome devtools consumption

@chenglou
Copy link
Member

Shipped!

EduardoRFS pushed a commit to EduardoRFS/bucklescript that referenced this issue Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants