Realm-js: Flow Type Integration

Created on 16 Apr 2017  路  2Comments  路  Source: realm/realm-js

Is there interest in a pull request to add flow type integration for Realm models (via Babel) or should it live in its own repository?

The general idea is this ...

import {Model} from "realm";

class Thunk extends Realm.Model {
  // @primaryKey
  id: string;
  name: string;
  // @indexed
  alive: boolean = false;
}

class Thing extends Realm.Model {
  // @primaryKey
  id: string;
  timestamp: ?Date;
  thunks: Thunk[];
}

... would compile to this ...

class Thunk {
  static schema = {
    name: "Thunk",
    primaryKey: "id",
    properties: {
      id: "string",
      name "string",
      alive: {type: "bool", indexed: true, default: false}
    },
  };
}

class Thing {
  static schema = {
    name: "Thing",
    primaryKey: "id",
    properties: {
      id: "string",
      timestamp {type: "date", optional: true},
      thunks: {type: "list", objectType: "Thunk"},
    },
  };
}

The realm.Model is just a _marker_ so we can identify which class to transform. We could also do something like this instead:

// @realm
class Thing {
  id: string;
}
O-Community Pipeline-Idea-Backlog T-Feature

Most helpful comment

Flow is quite popular now, do we accept the idea on this?

All 2 comments

Hi @mehcode. Thanks for writing in. Someone from the JavaScript team will review what you've shared and follow-up with you here regarding if it should be in here or if you'd create it in its own repo.

Flow is quite popular now, do we accept the idea on this?

Was this page helpful?
0 / 5 - 0 ratings