CodeVetter · Repo Unpack · Extension points
immerjs/immer
Extension mechanisms are concrete and mostly internal rather than a general third-party plugin API. The public library supports configurable instances and three enable functions, while internal typed interfaces connect implementations to scope behavior. Additional seams exist in draftable classes, producer abstractions, declaration mappings, packaging, documentation routing, and benchmark comparisons.
- New Immer instances provide independent auto-freeze, strict-copy, and iteration settings; produce is an instance arrow function, while the public singleton binds other exposed methods.
- The internal plugin registry has typed MapSet, Patches, and ArrayMethods slots; getPlugin rejects missing implementations and loadPlugin preserves the first loaded implementation.
- Collection extension hooks return draft/state tuples and provide fixSetContents; createProxy dispatches Maps/Sets through these hooks, and finalization calls collection cleanup.
- Array-method support plugs into objectTraps.get through detection and interceptor hooks; method Sets define dispatch, and registered handlers own operation flags, mutation bookkeeping, and return semantics.
- Custom classes opt into drafting by defining the exported immerable symbol on an instance or constructor; strict shallow copying preserves their prototype using descriptor-based Object.create.
- Libraries can build producer abstractions on createDraft/finishDraft and consume PatchListener output; these hooks reuse the same scope finalization rather than requiring a separate state engine.
- Public type behavior is concentrated in Draft, Immutable, IProduce, and IProduceWithPatches; distribution changes connect src/immer.ts exports to package conditions and tsup's format/declaration variants.
- Website additions join explicit sidebar lists and Docusaurus plugins/routes; performance-provider additions join benchmark imports, the private package dependencies, and current-build aliases.