LinusU / LinusU/swift-napi-bindings

More examples/documentation request

Open
#2 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
30
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Hey @LinusU! This package looks awesome, but beyond the simple examples it gets to be quite the exercise of seeing how you structured things. I'd love to use this package more but more advanced cases have me lost at present.

I've got a Swift class I'm defining that needs to event back to JS, through a `EventEmitter.emit(...)`. `EventEmitter`'s prototype is added to the NAPI class through `utils.inherit(...)` on the JS side before instantiation. I'm having a hard time seeing how this is possible without the object's receiver one would use with `napi_call_function`?

Here's the TypeScript...
```typescript

import * as utils from 'utils'
import { BindingClass } from ('.build/release/binding')

util.inherits(BindingClass, events.EventEmitter)

export { BindingClass }
```

You see, I need to access the `emit` function added to the `BindingClass` prototype.

```swift
class BindingClass: NSObject {
init(_ env: OpaquePointer) { ... }

func fireEvent(name: String) {
let emit = /* ... get JS emit function from self */

// Emit event
emit.call(env, name)
}
}
```

Any chance of more docs or examples with classes?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the package's existing simple examples and the TypeScript usage shown in the issue, especially utils.inherit, EventEmitter.emit, and napi_call_function. Trace how BindingClass and its Swift fireEvent method could be explained for a class that emits events to JavaScript. Done means adding an advanced class example or documentation that covers this EventEmitter use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift, typescript
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.