How simonerm/react-native-job-queue works
Project type and purpose
• This is a React Native library (“react-native-job-queue”) that provides a persistent job queue for RN apps.
• It exposes a JS/TypeScript API (Queue, Worker) and implements native modules on Android (Room/SQLite) and iOS (SQLite) to store and manage jobs persistently.
File structure
• Top-level “src” folder holds the TS code for the JS API: Queue.ts, Worker.ts, models, utils, and index.ts as the entrypoint.
• “android” folder holds the Android native module: Room-based entities (Job, JobDao, JobDatabase) plus RN module boilerplate (JobQueueModule, Package).
• “ios” folder holds the iOS native module: Swift/ObjC code wrapping SQLite database (JobQueue.swift, SQLiteDatabase.swift, SQLTable.swift) and the bridging header.
• “example” folder illustrates a full RN app using the library on both platforms.
• “docs” and “website” folders serve the API reference and website.
• Config files: podspec, Dockerfile/docker-compose (for website?), jest config and TS configs.
README for additional insights
• The README confirms: JS API + native persistence (SQLite) + Android Room.
• The library implements its own sqlite layers due to RN Pod constraints.
• No external network services; it’s embedded in the mobile app.
Main components and their interactions
a. JS Layer:
• Queue class: enqueue, dequeue, scheduling.
• Worker class: repeatedly polls Queue for jobs, runs handler functions.
• Models: Job, JobStore interface, utils (UUID, mocking).
b. React Native Bridge:
• JS <—> Native module boundary. Exposed methods like addJob, fetchJob, removeJob.
c. Android Native Module:
• Room database with Job entity, DAO, and JobDatabase.
• JobQueueModule exposes Room DAO calls to JS via ReactContextBaseJavaModule.
d. iOS Native Module:
• SQLiteDatabase that creates/checks tables (SQLTable).
• JobQueue.swift wraps insert/delete/query operations.
• Bridging header & Podspec exposes methods to RN.
e. Example App:
• Demonstrates instantiation of Queue and Worker in a real RN app.
f. Documentation Site:
• Static site generation (Docusaurus or similar, under “website”).
g. Testing:
• Jest tests for Queue and Worker in JS.
h. Build & Deployment:
• Android: gradlew, gradle scripts.
• iOS: Podspec, xcodeproj.
• CI: GitHub Actions (main.yml), Dockerfiles for website.
Architectural patterns and design principles
• Separation of concerns: JS API vs. native persistence.
• Bridge pattern: React Native bridge between layers.
• Repository/DAO pattern in Android (Room) and analogous wrapper in iOS.
• Event loop / polling pattern for the Worker.
• Modular design: core logic in “src”, platform-specific code in platform folders.