Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
noramass committed Jan 18, 2021
0 parents commit 2a69939
Show file tree
Hide file tree
Showing 16 changed files with 13,136 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "2"
checks:
argument-count:
config:
threshold: 6
complex-logic:
config:
threshold: 10
file-lines:
config:
threshold: 500
method-complexity:
config:
threshold: 10
method-count:
config:
threshold: 30
method-lines:
config:
threshold: 25
nested-control-flow:
config:
threshold: 4
return-statements:
config:
threshold: 4
similar-code:
config:
threshold: 100
identical-code:
config:
threshold: 75
plugins:
fixme:
enabled: true
config:
strings:
- FIXME
- XXX
- BUG
- TODO
git-legal:
enabled: true
nodesecurity:
enabled: true

exclude_patterns:
- "**/dist/"
- "**/node_modules/"
- "**/test/"
- "**/*.d.ts"
- ".mailmap"
- "**/*.md"
- "**/*polyfill*"
- "*conf*"
- "**/_*"
- "example/"
- "gulpfile*"
3 changes: 3 additions & 0 deletions .commitlint.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
41 changes: 41 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/eslintrc",
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"no-console": "error",
"no-debugger": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-inferrable-types": "off"
},
"overrides": [
{
"files": ["**/test/**/*.test.{j,t}s?(x)"],
"env": { "jest": true, "node": true },
"rules": {
"@typescript-eslint/ban-ts-comment": "off"
}
},
{
"files": ["example/**/*"],
"rules": {
"no-console": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
}
]
}
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# Operating Systems
.DS_Store
**/Thumbs.db

# NPM
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build Targets
/dist

# Local env files
.env.local
.env.*.local

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Jest test coverage
/coverage
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"printWidth": 100,
"endOfLine": "lf"
}
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
os: linux
language: node_js
cache: npm

jobs:
include:
- stage: release
node_js: lts/*
# before_script:
# - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
# - chmod +x ./cc-test-reporter
# - ./cc-test-reporter before-build
script:
- npm install
- npm run build
- npm run lint
# after_script:
# - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
deploy:
provider: script
cleanup: false
skip_cleanup: true
script: npx semantic-release
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/cfc752577cf502adf125/maintainability)](https://codeclimate.com/github/propero-oss/easy-store/maintainability)

# easy-store
React bindings for [@propero/easy-store](https://github.com/propero-oss/easy-store).

npm i @propero/easy-store-react

## Getting started
Using a store in a functional component:

```typescript jsx
import { createStore } from "@propero/easy-store";
import { useStore } from "@propero/easy-store-react";

const countStore = createStore(0);

// Every instance of counter will now use the same count value
export function Counter() {
const [count, setCount, updateCount] = useStore(countStore);

const increment = () => updateCount(count => count + 1);
const decrement = () => updateCount(count => count - 1);

return (
<>
<button type="button" onClick={decrement}>-</button>
<span>{count}</span>
<button type="button" onClick={increment}>+</button>
</>
);
}

export function MultipleCounters() {
return (
<>
<Counter />
<Counter />
</>
);
}
```

Using a subscribable:

```typescript jsx
import { createSubscribable } from "@propero/easy-store";
import { useSubscribable } from "src/use-subscribable";

const clickEvents = createSubscribable<[MouseEvent]>();
window.addEventListener("click", clickEvents.notify);

export function Popover({ target, open: initialOpen = false, children }: { target: HTMLElement; open?: boolean; children?: any }) {
const [open, setOpen] = useState(open);

function onMouseClick(ev: MouseEvent) {
setOpen(target === ev.target || target.contains(ev.target));
}

useSubscribable(clickEvents, onMouseClick);

return (
<div className="popover" style={{display: open ? "block" : "none"}}>
{children}
</div>
);
}
```
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const tsconfig = require("./tsconfig.json");
const { escapeRegExp, entries, fromPairs } = require("lodash");
const { paths } = tsconfig.compilerOptions;

const keyToRegexp = (key) => `^${escapeRegExp(key).replace("\\*", "(.*)")}$`;
const valueToPathMatcher = ([value]) => value.replace("*", "$1").replace("./", "<rootDir>/");
const entryMapper = ([key, value]) => [keyToRegexp(key), valueToPathMatcher(value)];
const moduleNameMapper = fromPairs(entries(paths).map(entryMapper));

module.exports = {
preset: "jest-preset-typescript",
collectCoverage: true,
collectCoverageFrom: ["src/**/*.ts", "!**/node_modules/**"],
coverageReporters: ["lcovonly"],
moduleNameMapper,
};
Loading

0 comments on commit 2a69939

Please sign in to comment.