Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-222

Stop polluting the global object

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      Goals

      In general its bad practice for a library to mutate objects without the developers consent, in particular it's bad practice for a plugin to write to the global object.

      Expected Results

      I expect Realm to not write to the global object.

      Actual Results

      Create a node project, install Realm and start the node REPL, notice how global.Realm gets set after Realm has been required.

      > global.Realm
      undefined
      > require("realm")
      { [Function: Realm]
        open: [Function: open],
        openAsync: [Function: openAsync],
        createTemplateObject: [Function: createTemplateObject],
        automaticSyncConfiguration: [Function],
        _extendQueryBasedSchema: [Function: _extendQueryBasedSchema] }
      > global.Realm
      { [Function: Realm]
        open: [Function: open],
        openAsync: [Function: openAsync],
        createTemplateObject: [Function: createTemplateObject],
        automaticSyncConfiguration: [Function],
        _extendQueryBasedSchema: [Function: _extendQueryBasedSchema] }
      

      Depending on this being a feature or a bug it might be a breaking change when its fixed.

      This looks like the offending line of code: https://github.com/realm/realm-js/blob/v2.23.0/src/js_realm.hpp#L421 but it also looks like there are a few parts of the code calling Object::get_global(ctx, "Realm") which is dependent on this global.

      Steps to Reproduce

      ☝️

      Code Sample

      ☝️

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.19.1
      • Node or React Native: N/A
      • Client OS & Version: N/A
      • Which debugger for React Native: N/A

            Assignee:
            Unassigned Unassigned
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: