GithubHelp home page GithubHelp logo

ivan3177 / react-native-mvvm-di Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 577 KB

React Native example based on MVVM+Dependency Injection+Feature sliced

Ruby 2.50% JavaScript 1.13% Starlark 0.97% Java 25.50% CMake 0.46% C++ 11.76% Shell 0.78% Objective-C 3.87% Objective-C++ 7.17% TypeScript 45.86%

react-native-mvvm-di's Introduction

React Native - MVVM example project

Purpose of this project

It is an example React Native application which shows how to create a modularized application with MVVM pattern, how to work with modules' entities in project, provide them via "improvised" dependency injection and how to structure your modularized app.

Uses:

  • react-native
  • react-navigation
  • mobx
  • axios

API

Uses Currency API for example purpose

Project Structure

  • src - all project source code

Project is split into modules

  • Navigation - provides all navigational config and structure(containers, types, service etc.)
  • shared - all shared data for modules(e.g. global project components)
  • core - main module for bootstrapping other modules
  • currencies - currency module(screens, api, data etc.)

Each module may consist of:

  • Services - utility classes for operations
  • API - api clients, network layer
  • Data - data sources, models, stores
  • Screens - modules' UI part, screens to be used in application's navigation
  • module.ts - module bootstrap(intializing and accessing other module's entities)

Each screen has:

  • components - screen-scope components(Component oriented pattern)
  • View - screen's UI, observer for ViewModel
  • ViewModel - all screen logic lives here, based on MobX. Provides all logic and data for View, accesses services, stores, data sources etc.
  • Screen - screen bootstrapping, props interface and options for navigation

Architecture

Application is based on Model-View-ViewModel architecture which provides the ability to split UI and logic

Each screen has View(UI) and ViewModel(logic). Model is currently a REST API provided to View Model through Data Source.

Data Source communicates with network by utilizing provided API client.

Navigation is encapsulated into service which provides View Models the ability to navigate through app(e.g. push new screen)

Navigation containers are based in Navigation module and have all Screens hierarchy in them.

Shared UI and logic are stored in Shared module.

Each module provides itself as lazy initiated singleton. For now all entities provided by modules are also lazy initiated singletons.

Module does not know anything about implementation details, it utilizes interfaces and requires configuration(with init static methods) which provides exact implementations of entities.

Core is a global modules registry. It(as all the modules) is a lazy initiated singleton, provides all modules as singletons. It does not know about exact modules implementation, utilizes module interfaces and requires configuration(with init static method) which provides modules factories.

Module's init method with exact entities implementations is invoked inside module's factory method. All entities are imported only at the moment of module's initialization so if module was not yet requested(and not initialized) then all it's entities(as well as module itself) will not yet be imported into runtime.

You can see graphical visualization of application's architecture below.

Architecture

Dependency graph

Dependency graph

Historical decisions

  • Ditched reflect metadata and decorator based IoC due to unexpected behavior and random bundling bugs
  • Use global module managers for direct class props injection

Possible improvements to project

  • Store API data in Models with persistence(by MobX store or any database, e.g. - WatermelonDB, Realm etc.)
  • Use RePack for chunked bundles, may be Module Federation
  • Add more modules, show module-module communication patterns(by utilizing other module's services, stores or by PubSub event-bus)

react-native-mvvm-di's People

Contributors

isokolovskii avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.