Skip to content

Commit

Permalink
feat: multi effects, smaller size, better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gdorsi authored and Guido D'Orsi committed Aug 26, 2021
1 parent 1c98dd6 commit e1bad3c
Show file tree
Hide file tree
Showing 25 changed files with 6,006 additions and 5,242 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
356 changes: 321 additions & 35 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-2.4.0.cjs

This file was deleted.

631 changes: 631 additions & 0 deletions .yarn/releases/yarn-3.0.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: '@yarnpkg/plugin-interactive-tools'

yarnPath: .yarn/releases/yarn-2.4.0.cjs
yarnPath: .yarn/releases/yarn-3.0.1.cjs
32 changes: 16 additions & 16 deletions devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
"lint": "web-ext lint"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.13.0",
"@babel/core": "^7.15.0",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@emotion/babel-preset-css-prop": "^11.2.0",
"@emotion/react": "^11.1.5",
"@emotion/react": "^11.4.1",
"@svgr/webpack": "^5.5.0",
"@types/react-inspector": "^4.0.1",
"@types/react-inspector": "^4.0.2",
"babel-loader": "^8.2.2",
"classnames": "^2.2.6",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^8.0.0",
"html-webpack-plugin": "^5.3.1",
"classnames": "^2.3.1",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"copy-webpack-plugin": "^9.0.1",
"html-webpack-plugin": "^5.3.2",
"raw-loader": "^4.0.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-json-tree": "^0.15.0",
"web-ext": "^6.0.0",
"webextension-polyfill-ts": "^0.25.0",
"webpack": "^5.25.0",
"webpack-cli": "^4.5.0",
"web-ext": "^6.3.0",
"webextension-polyfill-ts": "^0.26.0",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0",
"webpack-manifest-version-sync-plugin": "^0.0.4"
},
"webExt": {
Expand Down
72 changes: 40 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
{
"name": "@immobiliarelabs/state-atom",
"version": "0.2.0",
"description": "A minimal state management library for React inspired by Recoil.js",
"version": "0.3.0",
"description": "A decentralized state management library for React inspired by Recoil.js",
"homepage": "https://github.com/immobiliare/state-atom",
"keywords": ["react", "state-manager", "recoil", "recoiljs", "state"],
"keywords": [
"react",
"state-manager",
"recoil",
"recoiljs",
"state"
],
"scripts": {
"build": "microbundle --format module,cjs",
"dev": "microbundle --format module,cjs",
"build": "microbundle --format es,cjs",
"dev": "microbundle --format es,cjs",
"build:check-prod-size": "yarn build --define process.env.NODE_ENV='\"production\"'",
"lint": "eslint --fix --ignore-path .gitignore .",
"release": "HUSKY_SKIP_HOOKS=1 standard-version",
"next": "HUSKY_SKIP_HOOKS=1 standard-version --prerelease",
"test": "tap --coverage-report=html --no-browser --watch",
"test:ci": "tap --coverage-report=text-summary"
"test": "tap --coverage-report=html --no-browser --watch --no-check-coverage",
"test:ci": "tap --coverage-report=text-summary --no-check-coverage",
"postinstall": "is-ci || husky install",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable"
},
"repository": {
"type": "git",
Expand All @@ -25,38 +35,36 @@
"react": "^16.8.0 || ^17.0.0"
},
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@testing-library/react": "^11.2.5",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"@types/tap": "^14.10.3",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@testing-library/react": "^12.0.0",
"@types/react": "^17.0.19",
"@types/react-dom": "^17.0.9",
"@types/tap": "^15.0.5",
"@types/testing-library__react": "^10.2.0",
"@types/use-subscription": "^1.0.0",
"@typescript-eslint/parser": "^4.17.0",
"@typescript-eslint/parser": "^4.29.3",
"conventional-gitlab-releaser": "^4.0.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^4.3.8",
"jsdom": "16.4.x",
"lint-staged": "^10.5.4",
"husky": "^7.0.2",
"is-ci": "^3.0.0",
"jsdom": "^17.0.0",
"lint-staged": "^11.1.2",
"markdown-toc": "^1.2.0",
"microbundle": "^0.13.0",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"standard-version": "^9.1.1",
"sucrase": "^3.17.1",
"tap": "^14.11.0"
},
"dependencies": {
"dequal": "^2.0.2",
"use-subscription": "^1.5.1"
"microbundle": "^0.13.3",
"pinst": "^2.1.6",
"prettier": "^2.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"standard-version": "^9.3.1",
"sucrase": "^3.20.1",
"tap": "^15.0.9"
},
"resolutions": {
"typescript": "4.1.x"
Expand Down
36 changes: 36 additions & 0 deletions src/dequal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// from dequal/lite
export let hasOwnProperty = Object.prototype.hasOwnProperty;

export function dequal(foo: any, bar: any) {
let ctor, len;
if (foo === bar) return true;

if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
if (ctor === Date) return foo.getTime() === bar.getTime();
if (ctor === RegExp) return foo.toString() === bar.toString();

if (ctor === Array) {
if ((len = foo.length) === bar.length) {
while (len-- && dequal(foo[len], bar[len]));
}
return len === -1;
}

if (!ctor || typeof foo === 'object') {
len = 0;
for (ctor in foo) {
if (
hasOwnProperty.call(foo, ctor) &&
++len &&
!hasOwnProperty.call(bar, ctor)
)
return false;
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
return false;
}
return Object.keys(bar).length === len;
}
}

return foo !== foo && bar !== bar;
}
35 changes: 13 additions & 22 deletions src/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
/* istanbul ignore file */
import type { StateAtom } from '.';
function serialize(state: any) {
if (!state) return state;

function getAtomState(atom: StateAtom<any>) {
if (!atom.state) return atom.state;

return JSON.parse(JSON.stringify(atom.state));
return JSON.parse(JSON.stringify(state));
}

export function debugAtom(key: string, atom: StateAtom<any>) {
postMessage(
export function sendMessageToDevTools(
key: string,
type: 'NEW_ATOM' | 'UPDATE_ATOM',
value: any
) {
if (typeof window === 'undefined') return;

window.postMessage(
{
from: 'state-atom',
type: 'NEW_ATOM',
type,
key,
value: getAtomState(atom),
value: serialize(value),
},
'*'
);

atom.add(() => {
postMessage(
{
from: 'state-atom',
type: 'UPDATE_ATOM',
key,
value: getAtomState(atom),
},
'*'
);
});
}

0 comments on commit e1bad3c

Please sign in to comment.