Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

OpenCombine helpers for JavaScriptKit/WebAssembly APIs

License

swiftwasm/OpenCombineJS

Repository files navigation

OpenCombineJS

OpenCombine helpers for JavaScriptKit/WebAssembly APIs. Currently it provides:

Example

Here's an example of a timer that fetches a UUID from a remote server every second, parses it with JSValueDecoder, and then displays the result as text:

import JavaScriptKit
import OpenCombine
import OpenCombineJS
private let jsFetch = JSObject.global.fetch.function!
func fetch(_ url: String) -> JSPromise {
 JSPromise(jsFetch(url).object!)!
}
let document = JSObject.global.document
var p = document.createElement("p")
_ = document.body.appendChild(p)
var subscription: AnyCancellable?
let timer = JSTimer(millisecondsDelay: 1000, isRepeating: true) {
 subscription = fetch("https://httpbin.org/uuid")
 .publisher
 .flatMap {
 JSPromise(0ドル.json().object!)!.publisher
 }
 .mapError { 0ドル as Error }
 .map { Result<String, Error>.success(0ドル.uuid.string!) }
 .catch { Just(.failure(0ドル)) }
 .sink {
 let time = JSDate().toLocaleTimeString()
 switch 0ドル {
 case let .success(uuid):
 p.innerText = .string("At \(time) received uuid \(uuid)")
 case let .failure(error):
 p.innerText = .string("At \(time) received error \(error)")
 }
 }
}

Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to hello@swiftwasm.org.

About

OpenCombine helpers for JavaScriptKit/WebAssembly APIs

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Contributors 2

Languages

AltStyle によって変換されたページ (->オリジナル) /