1.0.19 • Published 1 year ago

act_mvvm_shop_cart v1.0.19

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Introduction

Shopping Cart NVVM pattern, Add and Reduce quantity and when quantity is Zero - button is disabled

Supported React Native and React Version

React Native

0.70.4

React

18.1.0

Installation

NPM

npm i act_mvvm_shop_cart

or Yarn

yarn add act_mvvm_shop_cart

Usage

import { CustomButton, CartItem } from 'act_mvvm_shop_cart'

or

import { CustomButton, CartItem } from 'act_mvvm_shop_cart/src/Components/Common_index'

Sample Code

You can use ItemCart like this with basic parameters,

  <View style={{ borderBottomWidth:2,marginBottom:10,flexDirection:"row"}}> 
        <ItemCart
            data = {data}
            addQty ={function}
            removeQty={function}
        />
    </View> 

And Let say you have a Data like this

const data = [
  {
      id:1,
      prodName:'Alaska',
      qty:0
  },
  {
      id:5,
      prodName:'Bear Brand',
      qty:3
  }]

Create a state for your data, this state will be use to update Quantity of your data, just set your constant variable of data in useState, sample code like this

const [cartData, setCartData] = useState(data)

And Create an Add Quantity function like this

const updateAddStatsInc = (id) => {
const isSelected = cartData.find((sel) => sel.id === id )

if (isSelected){
  let {qty} = isSelected
  isSelected.qty = qty+1
  setCartData([...cartData])
  
  console.log(cartData)
}else{
  data
}

}

And to Reduce Quantity, just change function name and change + into - sign, sample code like this

const updateReduceStatsInc = (id) => {
  const isSelected = cartData.find((sel) => sel.id === id )
  
  if (isSelected){
    let {qty} = isSelected
    isSelected.qty = qty - 1
    setCartData([...cartData])
    
    console.log(cartData)
  }else{
    data
  }

}

and now let's set function name into basic parameters of CartItem and set data into the useState we made

<View style={{ borderBottomWidth:2,marginBottom:10,flexDirection:"row"}}> 
        <ItemCart
            data = {cartData}
            addQty ={updateAddStatsInc}
            removeQty={updateReduceStatsInc
        />
</View>

Complete Code is look like this

import { StyleSheet, Text, View } from 'react-native'
import React, {useState} from 'react'
import { CustomButton, CartItem } from 'act_mvvm_shop_cart' 

const data = [
  {
      id:1,
      prodName:'Alaska',
      qty:0
  },
  {
      id:5,
      prodName:'Bear Brand',
      qty:3
  }]

const App = () => {
const [cartData, setCartData] = useState(data)

const updateAddStatsInc = (id) => {
  const isSelected = cartData.find((sel) => sel.id === id )
  
  if (isSelected){
    let {qty} = isSelected
    isSelected.qty = qty+1
    setCartData([...cartData])
    
    console.log(cartData)
  }else{
    data
  }

}
const updateReduceStatsInc = (id) => {
  const isSelected = cartData.find((sel) => sel.id === id )
  
  if (isSelected){
    let {qty} = isSelected
    isSelected.qty = qty - 1
    setCartData([...cartData])
    
    console.log(cartData)
  }else{
    data
  }

}

  return (
    <View style={{alignItems:'center'}}>

     <View style={{ borderBottomWidth:2,
        marginBottom:10,
        flexDirection:"row"}} >
      <CartItem
      data = {cartData}
      addQty ={updateAddStatsInc}
      removeQty={updateReduceStatsInc}
      />
    </View>
      
    </View>
  )
}

export default App

Node Version

v16.17.0

Screenshots

312314682_1477375882750818_1343012752205841344_n 313038449_463482755630492_2725771666647890915_n

Versioning Changelogs

Versions

Version 0.0.19 - update Versioning ChangeLogs and Supportive React Native Version and React version
Version 0.0.18 - update README.md
Version 0.0.17 - update Convention
Version 0.0.16 - update README.md
Version 0.0.16 - update Conventions
Version 0.0.15 - update package.json devDependency
Version 0.0.14 - update README.md
Version 0.0.13 - update components Path name into Pascal Case
Version 0.0.12 - update README.md
Version 0.0.11 - Update conventions
Version 0.0.10 - update README.md 
Version 0.0.9 - update Component Design
Version 0.0.8 - update README.md with Documentation of codes
Version 0.0.7 - update conventions
Version 0.0.6 - Update README.md
Version 0.0.5 - Applying Mini-app Conventions
Version 0.0.4 - Immutability of Redux
Version 0.0.3 - Add README.md
Version 0.0.2 - add builder bob to the package
Version 0.0.1 - Create Components of simple Shopping Cart
abababort-controlleracceptsacornacorn-jsxacorn-globalsacorn-walkajvabsolute-pathagent-baseansi-colorsansi-escapesanseraggregate-erroransi-fragmentsansi-regexansi-stylesanymatchappdirsjsargparsearr-diffarr-flattenarr-unionarray-unionarray-uniquearray-includesarray.prototype.flatmapasapassign-symbolsastral-regexast-typesasyncasynckitasync-limiteratobbabel-corebabel-eslintbabel-plugin-jest-hoistbabel-plugin-istanbulbabel-plugin-polyfill-corejs2babel-plugin-polyfill-corejs3babel-plugin-polyfill-regeneratorbabel-preset-current-node-syntaxbabel-plugin-syntax-trailing-function-commasbabel-preset-fbjsbabel-preset-jestbasebase64-jsbalanced-matchblbracesbrace-expansionbrowser-process-hrtimebrowserslistbserbuffercall-bindcaller-callsitebytescache-basebuffer-fromcallsitescaller-pathcamelcasecaniuse-litecapture-exitchalkchar-regexci-infoclass-utilscjs-module-lexerclean-stackcli-cursorcliuicli-spinnersclone-deepclonecocollection-visitcollect-v8-coveragecolor-convertcolor-namecolorettecombined-streamcommand-existscommandercommondirconcat-mapcomponent-emittercompressibleconnectconvert-source-mapcore-util-iscopy-descriptorcore-js-compatcosmiconfigcompressioncross-spawncssstylecssomdayjscsstypedata-urlsdebugdecamelizedecode-uri-componentdedentdecimal.jsdeepmergedeep-isdefaultsdefine-propertydefine-propertiesdeldenodeifydelayed-streamdepddetect-newlinediff-sequencesdestroydoctrinedir-globee-firstdomexceptionemitteryelectron-to-chromiumemoji-regexencodeurlend-of-streamerror-exenquirerenvinfoerrorhandleres-abstracterror-stack-parseres-to-primitivees-shim-unscopablesescaladeescodegenescape-htmleslint-config-prettierescape-string-regexpeslint-plugin-flowtypeeslint-plugin-eslint-commentseslint-plugin-jesteslint-plugin-reacteslint-plugin-prettiereslint-plugin-react-native-globalseslint-plugin-react-nativeeslint-plugin-react-hookseslint-scopeeslint-utilsesprimaeslint-visitor-keysesqueryesrecurseespreeestraverseesutilsetagevent-target-shimexec-shexecaexitexpand-bracketsexpectextend-shallowfast-globfast-deep-equalextglobfast-difffast-json-stable-stringifyfb-watchmanfastqfast-levenshteinfile-entry-cachefill-rangefinalhandlerfind-cache-dirfind-upflattedflat-cacheflow-parserfor-infragment-cachefreshform-datafs.realpathfs-extrafunction-bindfunction.prototype.namefunctional-red-black-treefunctions-have-namesget-caller-fileget-intrinsicgensyncget-package-typeget-stdinget-symbol-descriptionget-streamget-valueglob-parentglobalsglobglobbygraceful-fsgrowlyhashas-flaghas-bigintshas-property-descriptorshas-valuehas-symbolshas-tostringtaghermes-estreehas-valueshermes-parserhtml-encoding-snifferhosted-git-infohttp-errorshermes-profile-transformerhoist-non-react-staticshttp-proxy-agenthtml-escaperhuman-signalsiconv-litehttps-proxy-agentignoreieee754image-sizeimport-localimmerimport-freshimurmurhashinflightindent-stringinheritsinternal-slotis-accessor-descriptoris-absoluteipinvariantis-bigintis-boolean-objectis-bufferis-callableis-data-descriptoris-ciis-arrayishis-core-moduleis-date-objectis-descriptoris-directoryis-dockeris-generator-fnis-extglobis-fullwidth-code-pointis-extendableis-globis-git-dirtyis-interactiveis-git-repositoryis-negative-zerois-number-objectis-path-insideis-numberis-path-cwdis-potential-custom-element-nameis-streamis-regexis-shared-array-bufferis-plain-objectis-symbolis-stringis-relativeis-unc-pathis-unicode-supportedis-weakrefis-typedarrayis-windowsis-wslisarrayisexeisobjectistanbul-lib-reportistanbul-lib-instrumentistanbul-lib-coverageistanbul-lib-source-mapsistanbul-reportsjest-configjest-clijest-changed-filesjest-docblockjest-environment-nodejest-environment-jsdomjest-diffjest-eachjest-get-typejest-haste-mapjest-jasmine2jest-leak-detectorjest-matcher-utilsjest-message-utiljest-mockjest-pnp-resolverjest-regex-utiljest-resolvejest-runnerjest-resolve-dependenciesjest-snapshotjest-runtimejest-serializerjest-validatejest-utiljest-watcherjest-workerjetifierjs-yamljoijs-tokensjson-parse-better-errorsjsc-androidjsdomjscodeshiftjson-parse-even-better-errorsjsescjson-schema-traversejson5json-stable-stringify-without-jsonifyjsx-ast-utilsjsonfilelevnkind-ofkleurklawlines-and-columnslodash.mergelodash.truncatelevenlocate-pathlodash.debouncelodash.throttlelodashlog-symbolslogkittylru-cacheloose-envifymake-dirmap-cachemakeerrormemoize-onemerge-streammetro-babel-transformermap-visitmerge2metrometro-cachemetro-coremetro-file-mapmetro-cache-keymetro-configmetro-hermes-compilermetro-inspector-proxymetro-minify-uglifymetro-runtimemetro-react-native-babel-transformermetro-resolvermetro-source-mapmetro-transform-workermetro-transform-pluginsmicromatchmetro-symbolicatemimemime-dbmime-typesmixin-deepmimic-fnminimatchmsmkdirpminimistnatural-comparenegotiatornatural-compare-litenanomatchnice-tryneo-asyncnocachenode-dirnode-notifiernode-fetchnode-releasesnode-int64normalize-pathnwsapiobject-copyob1normalize-package-datanpm-run-pathnode-stream-zipobject-inspectobject-assignnullthrowsobject-keysobject-visitobject.entriesobject.assignobject.fromentriesobject.hasownobject.pickobject.valueson-finishedon-headersonceoptionatororaopenos-tmpdironetimep-each-seriesp-locatep-tryp-finallyp-limitp-mapparse-jsonparent-moduleparse5parseurlpascalcasepath-parsepath-keypath-is-absolutepath-existspath-typepifypicocolorspkg-dirpicomatchpiratesposix-character-classesprelude-lsprettierpretty-formatprettier-linter-helperspromiseprogressprocess-nextick-argspromptspslprop-typespunycodepumprange-parserquerystringifyreact-devtools-corequeue-microtaskreact-isreact-native-codegenreact-native-gradle-pluginreact-refreshreact-shallow-rendererread-pkgread-pkg-upreadlinerecastreadable-streamreduxredux-thunkregenerateregenerate-unicode-propertiesregenerator-transformregenerator-runtimeregexp.prototype.flagsregex-notregexppregjsgenregexpu-coreremove-trailing-separatorregjsparserrepeat-elementrepeat-stringrequire-directoryrequire-main-filenamerequire-from-stringrequires-portrestore-cursorreselectretresolveresolve-cwdresolve-fromresolve-urlrsvpreusifyrun-parallelrimrafsafe-regexsafe-buffersafe-regex-testsaxessafer-buffersanesemverschedulersendserve-staticserialize-errorset-valuesetprototypeofset-blockingshallow-cloneshebang-regexshebang-commandshell-quotesignal-exitshellwordsside-channelsisteransislashsnapdragonslice-ansisnapdragon-nodesnapdragon-utilsource-mapsource-map-urlsource-map-resolvesource-map-supportspdx-correctsplit-stringspdx-exceptionsspdx-expression-parsestack-utilsstackframesprintf-jsspdx-license-idsstatic-extendstatusesstring-widthstacktrace-parserstring.prototype.matchallstring_decoderstring-lengthstring.prototype.trimendstrip-ansistring.prototype.trimstartstrip-bomstrip-json-commentsstrip-eofstrip-final-newlinesupports-hyperlinkssudo-promptsymbol-treesupports-colorsupports-preserve-symlinks-flagtableterminal-linktemptext-tablethroattmplthrough2to-fast-propertiestest-excludeto-regexto-object-pathto-regex-rangetr46tslibtough-cookietsutilstoidentifiertype-detecttype-checktypedarray-to-buffertype-festuglify-esunc-path-regexunicode-match-property-ecmascriptunicode-canonical-property-names-ecmascriptunbox-primitiveunicode-match-property-value-ecmascriptunicode-property-aliases-ecmascriptunion-valueuniversalifyunset-valueunpipeurixurl-parseuseuse-sync-external-storeuri-jsutils-mergeuuidupdate-browserslist-dbutil-deprecatev8-compile-cachev8-to-istanbulvalidate-npm-package-licensevaryvlqwalkerw3c-xmlserializerw3c-hr-timewcwidthwhatwg-fetchwebidl-conversionswhatwg-encodingwhatwg-urlwhichwhich-modulewhatwg-mimetypewhich-boxed-primitivewrappywrite-file-atomicwrap-ansiword-wrapwsxml-name-validatory18nyallistyamlyargsyargs-parserxtendxmlcharsyocto-queue
1.0.19

1 year ago

1.0.18

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago