Skip to content

Commit e5a363c

Browse files
authored
fix: addAPI extensions should be late bound (#14)
instead of always keeping a reference to when the extensions were added.
1 parent 16710e6 commit e5a363c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

checkmate.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ in
145145
expected = [ ./tree/modules/hello-option/mod.nix ];
146146
};
147147

148+
addAPI."test API extensions are late bound" = {
149+
expr =
150+
let
151+
first = lit.addAPI { res = self: self.late; };
152+
extended = first.addAPI { late = _self: "hello"; };
153+
in
154+
extended.res;
155+
expected = "hello";
156+
};
157+
148158
pipeTo."test pipes list into a function" = {
149159
expr = (lit.map lib.pathType).pipeTo (lib.length) ./tree/x;
150160
expected = 1;

default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ let
8888
self: f:
8989
let
9090
__config = (f self);
91+
boundAPI = builtins.mapAttrs (_: g: g (self f)) __config.api;
9192
in
92-
__config.api
93+
boundAPI
9394
// {
9495
inherit __config;
9596
__functor = functor;
@@ -101,7 +102,7 @@ let
101102
matchNot = regex: self (c: mapAttr (f c) "filterf" (andNot (matchesRegex regex)));
102103
map = mapf: self (c: mapAttr (f c) "mapf" (compose mapf));
103104
addPath = path: self (c: mapAttr (f c) "paths" (p: p ++ [ path ]));
104-
addAPI = api: self (c: mapAttr (f c) "api" (a: a // builtins.mapAttrs (_: g: g (self f)) api));
105+
addAPI = api: self (c: mapAttr (f c) "api" (a: a // api));
105106

106107
# Configuration updates (non-accumulating)
107108
withLib = lib: self (c: (f c) // { inherit lib; });

0 commit comments

Comments
 (0)