From ff12264bf25763687e3aabe066214b80b6b6ab56 Mon Sep 17 00:00:00 2001 From: Vitalii Parovishnyk <870237+ikorich@users.noreply.github.com> Date: Fri, 12 Jun 2026 00:03:32 +0300 Subject: [PATCH] #24 docs(example): propagate Response.json this-binding fix to README and DocC The #24 fix landed in the CI-compiled main.swift but not the two copy-paste teaching examples. The DocC quick-start still showed the unbound jsonFn() call (throws "Illegal invocation" in browsers), and both README and DocC carried a stale JSPromise(resolver:) form (PromiseError-wrapped value + return .undefined) that diverged from the verified source. Both now mirror main.swift exactly. --- README.md | 4 ++-- Sources/OpenCombineJS/Documentation.docc/OpenCombineJS.md | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d59bc7c..d67aaa7 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ let timer = JSTimer(millisecondsDelay: 1000, isRepeating: true) { let jsonPromise = JSPromise(jsonObj) else { return JSPromise(resolver: { resolve in - resolve(.failure(JSPromise.PromiseError(.string("Unexpected response shape")))) - return .undefined + // Resolver rejection value is a raw JSValue (boxed into PromiseError downstream). + resolve(.failure(.string("Unexpected response shape"))) }).publisher } return jsonPromise.publisher diff --git a/Sources/OpenCombineJS/Documentation.docc/OpenCombineJS.md b/Sources/OpenCombineJS/Documentation.docc/OpenCombineJS.md index 5321272..b18fe6b 100644 --- a/Sources/OpenCombineJS/Documentation.docc/OpenCombineJS.md +++ b/Sources/OpenCombineJS/Documentation.docc/OpenCombineJS.md @@ -130,11 +130,12 @@ let timer = JSTimer(millisecondsDelay: 1000, isRepeating: true) { .flatMap { responseValue -> JSPromise.PromisePublisher in guard let obj = responseValue.object, let jsonFn = obj.json.function, - let jsonObj = jsonFn().object, + // `Response.json` must be called with the response as `this` (#24). + let jsonObj = jsonFn(this: obj).object, let jsonPromise = JSPromise(jsonObj) else { return JSPromise(resolver: { resolve in - resolve(.failure(JSPromise.PromiseError(.string("bad response")))) - return .undefined + // Resolver rejection value is a raw JSValue (boxed into PromiseError downstream). + resolve(.failure(.string("bad response"))) }).publisher } return jsonPromise.publisher