Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Naming conflicts between models and components

$
0
0

There are two conventional approaches I’ve seen in the wild and personally adopted

  1. Preface the file name with the directory name

    // Models__Comment.res
    type t = {
      author: string,
      content: string
    }
      
    let fetchById = (commentId) => // ...
    let fetchForPost = (postId) => // ...
    
    // Components__Comment.res
    @react.component
    let make = () => / /...
    
    

    Then export them in a single top-level file

    //Models.res
    module Comment = Models__Comment
    
    //Components.res
    module Comment = Components__Comment
    

    Then you can do stuff like
    Models.Comment.fetchById() or <Components.Comment/>

  2. You can utilize rewatch and monorepo.
    Rewatch let’s you split your code into different packages with their own rescript.json file, while still running a single compile step.

    // packages/models/rescript.json
    {
    ...
    "namespace": "Models"
    }
    
    // packages/components/rescript.json
    {
    ...
    "namespace": "Components"
    }
    

    Then you can have files with the same name, because they are in different namespaces


Viewing all articles
Browse latest Browse all 2592

Trending Articles