Skip to content

Commit

Permalink
feat: Throw errors when trying to use deprecated APIs (#168)
Browse files Browse the repository at this point in the history
* feat: Throw errors when trying to use deprecated APIs

* chore: Add deprecated APIs to types
  • Loading branch information
mrousavy authored Apr 17, 2024
1 parent 6953f65 commit 12919b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cpp/WKTJsiWorkletApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ class JsiWorkletApi : public JsiHostObject {
return func.call(runtime, nullptr, 0);
}

JSI_HOST_FUNCTION(createRunInJsFn) {
// TODO: Remove these deprecated APIs after one or two versions.
throw jsi::JSError(runtime,
"Worklets.createRunInJsFn(..) has been deprecated in "
"favor of Worklets.createRunOnJS(..) or "
"Worklets.runOnJS(..) - please migrate to the new API!");
}

JSI_HOST_FUNCTION(createRunInContextFn) {
// TODO: Remove these deprecated APIs after one or two versions.
throw jsi::JSError(runtime,
"Worklets.createRunInContextFn(context, ..) has been "
"deprecated in favor of context.createRunAsync(..) or "
"context.runAsync(..) - please migrate to the new API!");
}

JSI_HOST_FUNCTION(getCurrentThreadId) {
std::thread::id threadId = std::this_thread::get_id();
std::stringstream stream;
Expand Down Expand Up @@ -133,6 +149,10 @@ class JsiWorkletApi : public JsiHostObject {
JSI_EXPORT_FUNC(JsiWorkletApi, createContext),
JSI_EXPORT_FUNC(JsiWorkletApi, createRunOnJS),
JSI_EXPORT_FUNC(JsiWorkletApi, runOnJS),
JSI_EXPORT_FUNC(JsiWorkletApi,
createRunInContextFn), // <-- deprecated
JSI_EXPORT_FUNC(JsiWorkletApi,
createRunInJsFn), // <-- deprecated
JSI_EXPORT_FUNC(JsiWorkletApi, getCurrentThreadId),
JSI_EXPORT_FUNC(JsiWorkletApi, __jsi_is_array),
JSI_EXPORT_FUNC(JsiWorkletApi, __jsi_is_object))
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export interface IWorkletNativeApi {
*/
createSharedValue: <T>(value: T) => ISharedValue<T>;

/**
* @deprecated This API has been deprecated, use {@linkcode IWorkletContext.createRunAsync()} instead
*/
createRunInContextFn: never;
/**
* @deprecated This API has been deprecated, use {@linkcode createRunOnJS()} instead
*/
createRunInJsFn: never;

/**
* Creates a function that can be executed asynchronously on the default React-JS context.
*
Expand Down

0 comments on commit 12919b8

Please # to comment.