Skip to content
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

Generated Class Format #23

Open
lan-lyu opened this issue Aug 10, 2023 · 1 comment
Open

Generated Class Format #23

lan-lyu opened this issue Aug 10, 2023 · 1 comment
Labels

Comments

@lan-lyu
Copy link
Collaborator

lan-lyu commented Aug 10, 2023

I create 2 versions of generated data class example and its test.

Folder Structure

Each folder has 3 files

  1. __util__.ts: definiton of BaseObejct and methods
  2. data.ts: generated data class from TopLevelUnitSpec type
  3. test.ts: import methods in data.ts and generate JSON

Details

Data class with generic looks like this

class Data extends BaseObject<TopLevelUnitSpec<Field>> {

    constructor(value: TopLevelUnitSpec<Field>) {
        super();
        init(this);
        set(this, "data", value);
    }

When run test.ts

import * as VL from "./data";
const spec = VL.data("example.csv").autosize("fit").background("red").bounds("full");
console.log(VL.toJSON(spec));

The output is

{"data":"example.csv","autosize":"fit","background":"red","bounds":"full"}
@lan-lyu lan-lyu added the update label Aug 10, 2023
@domoritz
Copy link
Member

The generic version looks like a good start. Ideally we switch more of the any to be concrete types (for example in the get method). That will make the code safer to use and easier to debug. However, feel free to just add todo comments if you run into troubles and I can help.

@lan-lyu lan-lyu mentioned this issue Sep 29, 2023
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants