Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another ways to mark function as worklet. #1310

Merged
merged 6 commits into from
Oct 7, 2020

Conversation

Szymon20000
Copy link
Contributor

The pull-request adds two methods which are the new ways for telling babel that is should transform the function into a worklet. The first is useWorkletCallback:

useWorkletCallback(() => {...});

which is equivalent to

useCallback(() => {
  'worklet'
})

The second one is createWorklet which just lets us omit 'worklet' mark.

const worklet = createWorklet(() => {
  ...
});

behaves the same as

const worklet = () => {
   'worklet'
    ...
}

src/reanimated2/Hooks.js Outdated Show resolved Hide resolved
@terrysahaidak
Copy link
Contributor

I'll add TS typings in the following PR.

Co-authored-by: Terry Sahaidak <tasssik@gmail.com>
@jfrolich
Copy link
Contributor

jfrolich commented Oct 7, 2020

A note to make sure that it doesn't fail with this syntax:

import * as Reanimated from 'reanimated'

Reanimated.createWorklet(() => {
  ...
})

The reason is that ReasonML compiles to this syntax.

@terrysahaidak
Copy link
Contributor

terrysahaidak commented Oct 7, 2020

#1210 This PR should fix this type of imports as well.

cc @jakub-gonet @Szymon20000

@Szymon20000 Szymon20000 merged commit a15b8f9 into master Oct 7, 2020
@Szymon20000 Szymon20000 deleted the @szymon/createWorklet branch October 7, 2020 10:32
@mrousavy
Copy link
Contributor

mrousavy commented Oct 7, 2020

While I'm a big fan of this syntax, I think it would be a better name to shorten useWorkletCallback to useWorklet. A 'worklet' if per definition something like a callback anyways, no?

Thoughts @kmagiera @terrysahaidak @Szymon20000 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants