Skip to content

Releases: albertogasparin/react-magnetic-di

v3.2.0

29 Nov 00:14
Compare
Choose a tag to compare

New features

  • Add ability to mock (and auto-mock) modules via jest.mock

Improvements

  • Improve runtime performance by avoiding unnecessary arrays

v3.1.4

20 Aug 03:43
Compare
Choose a tag to compare

Bug fixes

  • Fix computed properties being renamed and throwing errors

v3.1.3

05 Aug 05:45
Compare
Choose a tag to compare

Bug fixes

  • Handle temporal deadzone for local variables shadowing parent function by @theKashey

v3.1.2

05 Jan 05:00
Compare
Choose a tag to compare

Bugfix

  • Ensure global injectables are cleaned up on render error

v3.1.0

15 Dec 04:24
Compare
Choose a tag to compare

New features

  • Added global prop to DiProvider that allows all use replacements to be available during the lifetime of the provider
  • Added global option to injectable(dep, mock, options) that allows a replacement to be available during the lifetime of the provider

v3.0.1

12 Sep 04:12
Compare
Choose a tag to compare

Bugfix

  • Fixed a bug when using Babel plugin in conjunction CommonJS babel transform, with multiple di locations not working

v3.0.0

01 Aug 23:49
Compare
Choose a tag to compare

New features

This new version of react-magnetic-di comes with tons of goodies!

  • Automatic injection. Until now, di() needed to be called in every function to enable injection and, moreover, it needed to contain all the values allowed for injection. It was a safe strategy but it was suboptimal. This version of magnetic-di enables injection without di()
  • Support for injecting anywhere. While the pkg name is still referencing React, this version exposes runWithDi which enables replacement in any context
  • Injectable level targeting. With the new option injectable(A,B, { target: C }) you can replace a dependency only in a particular function scope.
  • New ESLint rule no-restricted-injectable. Allows to warn/error about dangerous injectable patterns (eg on very commonly used dependencies)

Breaking changes

  • No more babel-plugin-macro support, as di() is now implicit
  • Removed exhaustive-inject ESLint rule as no longer needed
  • Change in Babel configuration

Migration from v2

The most substantial change is the different Babel plugin configuration. To facilitate the migration, you can maintain the previous behaviour by excluding all files from auto injection:

// In your .babelrc / babel.config.js
  // ... other stuff like presets
  plugins: [
    // ... 
    ['react-magnetic-di/babel-plugin', { exclude: [/.*/], enabledEnvs: ['development', 'test'] }],
  ],

Then, you can start excluding less from auto injection, only leaving test and mock files (we recommend it, to reduce chances of loops due to injectables injecting themselves). In case you hit an issue with auto di, you can opt out in a specific function by adding the magic comment // di-ignore

v2.3.4

30 May 09:42
Compare
Choose a tag to compare

Fix an issue with stats and the undocumented missing() tracking functionality.

v2.3.3

17 May 06:17
Compare
Choose a tag to compare

Fix bad injectables

So far, we forgot to enforce that values passed in as injectables were actual injectables. So DiProvider would accept anything and not flag that the provided value will be ignored. This releases fixes that. It will complain/break some tests but those "injectables" were not working anyway.

A side effect is a breaking change on one TS type: if you were using Dependency before in your project, you'll likely have to replace it with Injectable, as the latter is more strict.

v2.3.2

15 May 04:37
Compare
Choose a tag to compare

Fix

  • Add support for injectable additional config argument:
    • { displayName: 'MyComponentName' } custom displayName for components / functions
    • { track: false } ignore injectable on stats.unused()