Coder Social home page Coder Social logo

hall-of-fame's Introduction

hall of fame

Build Status badge-lines badge-branches badge-functions badge-statements

directory structure

  • @shared
    • components
    • services
  • src
    • screens
    • components
    • services
    • utils
    • assets

@shared

include all component and services that can be used in other projects

it better if we can create an library for this

see @shared docs

screens

  • all screen should be create in this directory

  • to create screen

    • first create a folder inside screens
    • then create screen file inside that folder. and make sure screen file name ends with 'Screen'.

components

  • include all app specific components.
  • screen specific component like list item component should be in their screen directory.

#how to add new screen

a simple screen should be like below

import {INavigationService} from '@shared';
import React from 'react';
import {View, Text, StyleSheet} from 'react-native';

export type ParamsType = {
    
}

export type ScreenNameProps = 
... &
ParamsType

@observer
exportW class ScreenName extends React.Component<ScreenNameProps> {
    static readonly RouteName = 'ScreenName';

    static start(nav: INavigationService,params:ParamsType) {
        nav.navigate(ScreenName.RouteName,params);
    }

    render() {
        return (
           ...
        )
    }
}


const styles = StyleSheet.create({
    ...
});
  • should have an static filed for RouteName;
  static readonly RouteName = 'ScreenName';
  • should have one or more starter method to show witch param need to passed to screen

     ```typescript
     static start(nav: INavigationService) {
         nav.navigate(this.RouteName);  // to access to static class property from static method should use this
     }
     ```
     or start with params
     ```typescript
     static start(nav: INavigationService,params:ParamsType) {
         nav.navigate(ScreenName.RouteName,params);
     }
     ```
    

#How to add new screen to navigator

wrap screen component in navigationParamsToProps HOC and then add it to AppNavigator routes

#where to add test file test file should be create beside the test target file and ends with .test.tsx or .test.ts

assets

all assets files should be in this directory see document for more details see assets docs

services

if you have reusable logic maybe you need a service

for example AuthService can be written to save and update token or check for current loggedIn state

all service should init in App.tsx so all component can access them.

how to create service

create a folder for that in services directory. then create file for it

each service most implement IService interface

for most case can extend BaseService class.

then add service to App.tsx

service name use in DI should be started $ so we dont have any conflict with normal component props

how to use service

inject service by @DIInject('$name') decorator into your component.

then you access service in component props. (this.props.$name)

naming conventions

name convention example
component PascalCase TextInput
component file PascalCase.jsx TextInput.tsx
test file $targetName.test TextInput.test.tsx
store file $targetName.store TextInput.store.ts
folder dash-case text-input
instance camelCase let textInputStore

binding this

you can use auto binding decorator @autobind to bind all method of class or single method

do not bind react component class because may override lifecycle binding

mobx

  • decorate any component that may use observable value.
    • if you dont know it use observable or not then decorate it :)

    • decorate component with @observer help to mobx to rerender it if any of observable value changed and improve performance.

    • @observershould be the first decoration add other above it

        @DIInject('$store') // to optional injection or inject(''$store) to throw erro of can not inject
        @observer // should be the first one
        class MyComponent extends React.Component { ...
    
    • you can use Provider component to provide dependency (it use in App.tsx check it)

for more info @see mobx docs

npm or yarn ?

we use yarn as package manager

type or interface ?

we prefer type unless you really need interface (need to be implemented)

  • if you want describe some model use type
  • if you want some class implement your model use interface (interface name should be started with capital I)

hall-of-fame's People

Contributors

ahmaddehnavi avatar

Watchers

 avatar

Forkers

dgross881

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.