6.0.3 • Published 4 years ago

@randajan/react-app-core v6.0.3

Weekly downloads
150
License
MIT
Repository
github
Last release
4 years ago

@randajan/react-app-core

Pack of core system for react application

NPM JavaScript Style Guide

Install

npm install --save @randajan/react-app-core

About

I'm not exepcting that anyone will reach this page or even try this package. But i love javascript and it was challange and fun to create this.

This package easily can:

  • Get, add, remove keys in query string
  • Store data
  • Reach browser data
  • Setup Rest Api
  • Authorize OAuth user
  • Manage languages

Maybe later I will break it into the small standalone libraries, but now it's just about to kill two birds with one stone

Example

import React, { Component } from 'react'

import CoreProvider, {useCore} from '@randajan/react-app-core'

const langLibs = [
    {
      priority:10,
      list:["en", "cs", "any"],
      fetch:lang=>fetch("/"+lang+".json").then(data=>data.json())
    },
];

const viewSizes = {
  xxs:(weight, height) => weight <= 500 && height < 100
}

const coreConfig = {
  nocache:true,
  version:"1.0.0.0",
  debug:true,
  onChange:_=>alert(_),
  cryptKey:"XYZ",
  langList:["de", "en"],
  langLibs
  langFallback:"en",
  langDefault:"en",
  viewSizes,
  sessionUrl:"/session",
  apiUrl:"http://api.example.com",
  authPath:"/auth",
  authProviders:["google", "facebook"]
  iconsPrefix:"ico",
  iconsList:{user:require("user.svg")},
  iconsSize:24
  anonymUser:{name:"Ishtvan"}
}

import CoreProvider, { useLang, useUser, Ico } from "@randajan/react-app-core";

export default class App extends Component {
  render () {
    return (
      <CoreProvider {...coreConfig}>
        <Consumer/>
      </CoreProvider>
    )
  }
}

function Consumer() {
  const Lang = useLang();
  const User = useUser();

  return (
    <div className="User">
      <Ico src="user" className="avatar" title="User"/>
      <p className="label">{Lang.get("auth.anonym")}</p>
      <p className="name">{User.get("name")}</p>
    </div>
  )
}

Core Props

nametypedefaultuse
versionString-Version will be stored with other cached data. If there will be mismatch cached data will be forgotten
nocacheBooleanfalseOn true will not store any data in localStorage. Great for development purpose
debugBooleanfalseWill append jet and core to global scope and every onChange event output to console
onChangeFunction-After any change of core state will be called with list of changes
onBuildFunction-Run after initial build
cryptKeyString-Will be used for crypting and decrypting User data
langListArray || Object["en"]Define available languages. It will auto include langFallback and langDefault
langLibsArray*Define lang ibrary for fetch lang when it's selected
langFallbackString"en" || first in langListDefine fallback on lang when there is no text in selected lang
langDefaultStringfirst in langListDefault language
viewSizesObject**Define constants for measure inner window size
sessionUrlString-Define path to session storage. If it's not present it will use localStorage
apiUrlString-Define rest api url
authPathString-Define oAuth path for resolve AuthCode
authProvidersArray-oAuth providers
anonymUserObject-Anonym user profile
iconsPrefixStringIcoSVG icons prefix is used as default classname of all icons
iconsListObject || Array-path to all used SVG icons {icon_className:icon_file}
iconsSizeNumber24viewBox of all SVG icons. Every used icon must be same size!
imagesPrefixStringImgimages prefix is used as default classname of all icons
imagesListObject || Array-path to all used images {image_className:image_file}
addPropsFunction-First argument is function which calling Core.regOnChange(onChange, ...modules)

**default langLibs:

{
  priority:-1,
  path:"",
  list:["cs", "en", "de"],
  fetch:lang => require("./lang/"+lang).default)
}

**default viewSizes:

const DEFAULTSIZES = {
    xs: w=>w<=600,
    s: w=>w>600&&w<=960,
    m: w=>w>960&&w<=1280,
    l: w=>w>1280&&w<=1920,
    xl: w=>w>1920,

    gtXs: w=>w>600,
    gtS: w=>w>960,
    gtM: w=>w>1280,

    ltM: w=>w<=960,
    ltL: w=>w<=1280,
    ltXl: w=>w<=1920
}

Initial Core modules

nameparentpurpose3rd scripts
Core-Container for everythingHelmet
TrayCoreHandle and log every Core Task such as initialization process, loading modules, login user and selecting lang-
PageCoreCollecting information about page like path, title, query, hashquery-string
Crypt-Take care of crypting and decrypting everythingcrypt-js
ScreenCoreCollecting information about screen size-
ClientCoreCollecting information about clientreact-device-detect
AuthCoreManage Users and authorization via oauth-
UserAuthKeep user profile-
ApiCoreShorthand for fetching data from Rest Api-
LangCoreResponsible for select language, fetch external lang libraries and provide right textmoment
IconsCoreFetch and cache svg icons
ImagesCoreFetch images

*every script uses @randajan/react-jetpack

Exports

export default CoreProvider;
export {
  jet,
  css,

  Base,
  Serf,

  Api,
  Auth,
  Core,
  Icons,
  Images,
  Lang,
  Page,
  Screen,

  Crypt,
  LangLib,

  Ico,
  Img,
  CoreProvider,

  ModalProvider,
  Modal,
  PopUp,
  Pop

}

License

MIT © randajan

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.7.21

5 years ago

5.7.20

5 years ago

5.7.19

5 years ago

5.7.18

5 years ago

5.7.17

5 years ago

5.7.16

5 years ago

5.7.15

5 years ago

5.7.14

5 years ago

5.7.13

5 years ago

5.7.13-0

5 years ago

5.7.12-0

5 years ago

5.7.11-0

5 years ago

5.7.10-0

5 years ago

5.7.9

5 years ago

5.7.8

5 years ago

5.7.7

5 years ago

5.7.6

5 years ago

5.7.5

5 years ago

5.7.4

5 years ago

5.7.3

5 years ago

5.7.2

5 years ago

5.7.1

5 years ago

5.7.0

5 years ago

5.6.2

5 years ago

5.6.1

5 years ago

5.6.0

5 years ago

5.5.2

5 years ago

5.5.1

5 years ago

5.5.0

5 years ago

5.4.5

5 years ago

5.4.4

5 years ago

5.4.3

5 years ago

5.4.2

5 years ago

5.4.1

5 years ago

5.4.0

5 years ago

5.3.0

5 years ago

5.2.14

5 years ago

5.2.13

5 years ago

5.2.12

5 years ago

5.2.11

5 years ago

5.2.10

5 years ago

5.2.9

5 years ago

5.2.8

5 years ago

5.2.7

5 years ago

5.2.6

5 years ago

5.2.5

5 years ago

5.2.4

5 years ago

5.2.3

5 years ago

5.2.2-0

5 years ago

5.2.2

5 years ago

5.2.1-0

5 years ago

5.2.0-0

5 years ago

5.1.7

5 years ago

5.1.6

5 years ago

5.1.6-0

5 years ago

5.1.5-0

5 years ago

5.1.4-0

5 years ago

5.1.3

5 years ago

5.1.2

5 years ago

5.1.1

5 years ago

5.1.0-0

5 years ago

5.1.1-0

5 years ago

5.0.14-0

5 years ago

5.0.13-0

5 years ago

5.0.12-0

5 years ago

5.0.11-0

5 years ago

5.0.10-0

5 years ago

5.0.9-0

5 years ago

5.0.8-0

5 years ago

5.0.7-0

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

5.0.0-0

5 years ago

4.1.7

5 years ago

4.1.6

5 years ago

4.1.5

5 years ago

4.1.4

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.0.6

5 years ago

4.1.0

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.8.6

5 years ago

2.8.5

5 years ago

2.8.4

5 years ago

2.8.3

5 years ago

2.8.2

5 years ago

2.8.1

5 years ago

2.8.0

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.1

5 years ago

2.5.2

5 years ago

2.6.0

5 years ago

2.6.3

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago