Skip to content

Commit

Permalink
Merge pull request #54 from shipt/development
Browse files Browse the repository at this point in the history
Release 1.0.2
  • Loading branch information
chaceburnette authored Apr 7, 2021
2 parents 49072a8 + 0174062 commit d97806a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
35 changes: 23 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ defaults: &defaults
docker:
- image: circleci/node:12.16.1

install_dependencies: &install_dependencies
run:
name: Install Dependencies
command: cd osmosis; yarn

build_osmosis: &build_osmosis
run:
name: Build
command: cd osmosis; yarn build

generate_types: &generate_types
run:
name: Generate Types
command: cd osmosis; yarn generateTypes



jobs:
test:
<<: *defaults
steps:
- checkout
- run:
name: Install Osmosis Dependencies
command: cd osmosis; yarn
- run:
name: Build Osmosis
command: cd osmosis; yarn build
- <<: *install_dependencies
- <<: *build_osmosis
- <<: *generate_types
- run:
name: Install React Example Dependencies
command: cd examples/counter-react; yarn
Expand All @@ -26,15 +40,12 @@ jobs:
<<: *defaults
steps:
- checkout
- run:
name: Install Dependencies
command: cd osmosis; yarn
- <<: *install_dependencies
- <<: *build_osmosis
- <<: *generate_types
- run:
name: Authenticate with registry
command: cd osmosis; echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
- run:
name: build
command: cd osmosis; yarn build
- run:
name: Publish package
command: cd osmosis; npm publish --access public
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## v1.0.2

* Added generated type declarations

## v1.0.1

* Cleaning up some unused files
Expand Down
4 changes: 4 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [Chace Burnette](https://github.com/chaceburnette)

### [Joshua Griffin](https://github.com/joshuakg)

### [Tom Mahle](https://github.com/TomMahle)

### [Jakhongir Khusanov](https://github.com/jkhusanov)
6 changes: 4 additions & 2 deletions osmosis/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@shipt/osmosis",
"version": "1.0.1",
"version": "1.0.2",
"description": "A lightweight state management library for React and React Native",
"keywords": ["react", "react native", "state management", "hooks", "state persistence", "shipt"],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/shipt/osmosis",
"bugs": "https://github.com/shipt/osmosis/issues",
"repository": "https://github.com/shipt/osmosis.git",
Expand All @@ -23,7 +24,8 @@
"dist"
],
"scripts": {
"build": "babel src -d dist"
"build": "babel src -d dist",
"generateTypes": "npx typescript ./src/index.js --declaration --allowJs --emitDeclarationOnly --outDir dist"
},
"peerDependencies": {
"react": "^16.8.0"
Expand Down
14 changes: 12 additions & 2 deletions osmosis/src/setupStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ class Container {
}
}

const setupStore = (useHook, classContainer) => {
/**
* @callback useCustomHook
* @returns {Object}
*/

/**
* @param {useCustomHook} useCustomHook
* @param {Object=} classContainer - Deprecated: classContainer support will be removed in a future release
* @returns {Object[]}
*/
const setupStore = (useCustomHook, classContainer) => {
const StoreContext = createContext();
let store = { state: {} };

const withStoreContext = WrappedComponent => props => {
let container = useHook();
let container = useCustomHook();
if (classContainer) {
classContainer.container = container;
} else {
Expand Down
5 changes: 5 additions & 0 deletions osmosis/src/storeProvider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @param {Object[]} storeProviders
* @param {Object} componentToWrap
* @returns {Object} wrappedComponent
*/
export const StoreProvider = (storeProviders, wrappedComponent) => {
if(!Array.isArray(storeProviders)) throw new Error('StoreProvider requires an array of wrapper functions')
if(!wrappedComponent) throw new Error('StoreProvider requires a component to wrap')
Expand Down
24 changes: 24 additions & 0 deletions osmosis/src/usePersistedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { useState, useEffect } from 'react';
let getItem;
let setItem;

/**
* @param {Object} initValue
* @param {string} key
* @returns {Object[]}
*/
export const usePersistedState = (initValue, key) => {
if (!key) console.error('usePersistedState: Storage key is required');

Expand Down Expand Up @@ -39,6 +44,25 @@ export const usePersistedState = (initValue, key) => {
return [state.value, setPersistedState, state.isLoaded];
};


/**
* @callback getItem
* @param {string} key
* @returns {Promise} Promise<value>
*/

/**
* @callback setItem
* @param {string} key
* @param {Object} value
* @returns {Promise} Promise<>
*/

/**
* @param {Object} config
* @param {getItem} config.getItem
* @param {setItem} config.setItem
*/
export const configureUsePersistedState = config => {
getItem = config.getItem;
setItem = config.setItem;
Expand Down

0 comments on commit d97806a

Please sign in to comment.