Skip to content

[core][iOS] Add StaticFunction and StaticAsyncFunction to Class in modules API#38754

Merged
jakex7 merged 5 commits intomainfrom
@jakex7/iosDslStaticFunctions
Oct 20, 2025
Merged

[core][iOS] Add StaticFunction and StaticAsyncFunction to Class in modules API#38754
jakex7 merged 5 commits intomainfrom
@jakex7/iosDslStaticFunctions

Conversation

@jakex7
Copy link
Copy Markdown
Member

@jakex7 jakex7 commented Aug 12, 2025

Why

It should be possible to create a static functions on SharedObjects

How

Add StaticFunction and StaticAsyncFunction in DSL and decorate the class constructor with them.

Test Plan

  • Tests should pass
  • Add static functions to shared object

Checklist

@jakex7 jakex7 requested a review from lukmccall August 12, 2025 13:21
@github-actions
Copy link
Copy Markdown
Contributor

Subscribed to pull request

File Patterns Mentions
packages/expo-modules-core/** @Kudo, @lukmccall

Generated by CodeMention

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Aug 12, 2025
@expo-bot
Copy link
Copy Markdown
Collaborator

expo-bot commented Aug 12, 2025

The Pull Request introduced fingerprint changes against the base commit: 6be2724

Fingerprint diff
[
  {
    "op": "changed",
    "beforeSource": {
      "type": "dir",
      "filePath": "../../packages/expo-modules-core",
      "reasons": [
        "expoAutolinkingIos",
        "expoAutolinkingAndroid"
      ],
      "hash": "49fa089379ae54b1cbb9dfff3960bead61efbd17"
    },
    "afterSource": {
      "type": "dir",
      "filePath": "../../packages/expo-modules-core",
      "reasons": [
        "expoAutolinkingIos",
        "expoAutolinkingAndroid"
      ],
      "hash": "81925512cd02102f741e642d53957db2fb08da0b"
    }
  }
]

Generated by PR labeler 🤖

@jakex7 jakex7 requested a review from Kudo August 13, 2025 10:39
Copy link
Copy Markdown
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question: what is the static function in this context? is that a function binding to the shared object instance and not binding to object's prototype?

@jakex7
Copy link
Copy Markdown
Member Author

jakex7 commented Aug 13, 2025

@Kudo: quick question: what is the static function in this context? is that a function binding to the shared object instance and not binding to object's prototype?

It's function bound to the object's constructor, making it the 'standard' javascript static method on a class.

For example, we could have a shared object called File that includes a static function create, which creates a new instance so it could be used like File.create(path)

@Kudo
Copy link
Copy Markdown
Contributor

Kudo commented Aug 13, 2025

It's function bound to the object's constructor, making it the 'standard' javascript static method on a class.

For example, we could have a shared object called File that includes a static function create, which creates a new instance so it could be used like File.create(path)

cool, thanks for this clarification. wdyt to rename it as ClassStaticFunction to make it clearer?

@jakex7 jakex7 requested review from lukmccall and removed request for lukmccall August 28, 2025 15:11
@Kudo
Copy link
Copy Markdown
Contributor

Kudo commented Aug 28, 2025

wdyt to rename it as ClassStaticFunction to make it clearer?

@jakex7 did you consider this option? when i first seen this i was confused what the "static" until you explained it. i guess ClassStaticFunction would be a clearer name.

@jakex7
Copy link
Copy Markdown
Member Author

jakex7 commented Sep 1, 2025

wdyt to rename it as ClassStaticFunction to make it clearer?

@jakex7 did you consider this option? when i first seen this i was confused what the "static" until you explained it. i guess ClassStaticFunction would be a clearer name.

@Kudo

Sorry for not responding earlier. Yes, I’ve considered that, but I’m not sure if it’s the best approach. It can only be used within a Class context, so that does imply it’s class-related. On the other hand, we don’t typically use the "Class" prefix for other elements - for example, we use Property instead of ClassProperty. That said, I don’t have a strong opinion either way. If you still think that renaming it would improve clarity, I’m happy to make the change.

@Kudo
Copy link
Copy Markdown
Contributor

Kudo commented Sep 2, 2025

On the other hand, we don’t typically use the "Class" prefix for other elements - for example, we use Property instead of ClassProperty

wait. i was thinking that Property is binded to instance, not class itself . from the example, it looks like

object = new expo.modules.TestModule.Counter(0);
object.currentValue

does it also work like expo.modules.TestModule.Counter.currentValue?

@jakex7 jakex7 force-pushed the @jakex7/iosDslStaticFunctions branch from ac6face to e8c474b Compare October 17, 2025 11:51
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Oct 17, 2025
jakex7 added a commit that referenced this pull request Oct 20, 2025
…n modules API (#39228)

# Why

Follow-up for #38754

It should be possible to create a static functions on SharedObjects

# How

Add `StaticFunction` and `StaticAsyncFunction` in DSL and decorate the
class constructor with them.

# Test Plan

* Tests should pass
* Add static functions to shared object
@jakex7 jakex7 force-pushed the @jakex7/iosDslStaticFunctions branch from 6b97739 to 92fd6a5 Compare October 20, 2025 10:08
@jakex7 jakex7 merged commit 8b498ee into main Oct 20, 2025
10 of 13 checks passed
@jakex7 jakex7 deleted the @jakex7/iosDslStaticFunctions branch October 20, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants