-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for JSKit 0.11.1, add async
task
modifier (#457)
I've also moved sources in `TokamakDemo` directory into their respective subdirectories for easier navigation. * Update for JSKit 0.11.0, add async `task` modifier * Add back new file locations to `NativeDemo` * Add compiler `#if` check to `TaskDemo` * Update to JavaScriptKit 0.11.1 * Restrict `TaskDemo` with `compiler(>=5.5)` check * Replace `compiler` with `swift` in some places * Revert "Replace `compiler` with `swift` in some places" This reverts commit 534784c. * Use Xcode 13.2 on GitHub Actions hosts * Find `TokamakPackageTests` in the build directory * Fix macOS tests bundle path * Make `task` modifier available only on macOS Monterey * Revert "Use Xcode 13.2 on GitHub Actions hosts" This reverts commit 63d044f. * Revert "Fix macOS tests bundle path" This reverts commit 3ccbc98. * Revert "Find `TokamakPackageTests` in the build directory" This reverts commit 68c845b. * Use `canImport(Concurrency)` as an ultimate check * Use `compiler(>=5.5) && canImport(Concurrency)` * Clarify new browser version requirements in `README.md` * Account for `_Concurrency` naming * Update `README.md` * Update README.md Co-authored-by: ezraberch <49635435+ezraberch@users.noreply.github.com>
- Loading branch information
1 parent
a5a05b4
commit cbfdc34
Showing
46 changed files
with
442 additions
and
225 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2021 Tokamak contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#if compiler(>=5.5) && (canImport(Concurrency) || canImport(_Concurrency)) | ||
|
||
public extension View { | ||
func task( | ||
priority: TaskPriority = .userInitiated, | ||
_ action: @escaping @Sendable () async -> () | ||
) -> some View { | ||
var task: Task<(), Never>? | ||
return onAppear { | ||
task = Task(priority: priority, operation: action) | ||
} | ||
.onDisappear { | ||
task?.cancel() | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 Tokamak contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import TokamakShim | ||
|
||
struct ShadowDemo: View { | ||
var body: some View { | ||
Color.red.frame(width: 60, height: 60, alignment: .center) | ||
.shadow(color: .black, radius: 5, x: 0, y: 10) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2021 Tokamak contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#if os(WASI) && compiler(>=5.5) && (canImport(Concurrency) || canImport(_Concurrency)) | ||
import JavaScriptKit | ||
import TokamakDOM | ||
|
||
private let jsFetch = JSObject.global.fetch.function! | ||
private func fetch(_ url: String) -> JSPromise { | ||
JSPromise(jsFetch(url).object!)! | ||
} | ||
|
||
private struct Response: Decodable { | ||
let uuid: String | ||
} | ||
|
||
struct TaskDemo: View { | ||
@State private var response: Result<Response, Error>? | ||
|
||
var body: some View { | ||
VStack { | ||
switch response { | ||
case let .success(response): | ||
Text("Fetched UUID is \(response.uuid)") | ||
case let .failure(error): | ||
Text("Error is \(error)") | ||
default: | ||
Text("Response not available yet") | ||
} | ||
|
||
Button("Fetch new UUID asynchronously") { | ||
response = nil | ||
Task { await fetchResponse() } | ||
} | ||
}.task { | ||
await fetchResponse() | ||
} | ||
} | ||
|
||
func fetchResponse() async { | ||
do { | ||
let fetchResult = try await fetch("https://httpbin.org/uuid").value | ||
let json = try await JSPromise(fetchResult.json().object!)!.value | ||
response = Result { try JSValueDecoder().decode(Response.self, from: json) } | ||
} catch { | ||
response = .failure(error) | ||
} | ||
} | ||
} | ||
#endif |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.