10000 Reduce bundle size by becomingbabyman · Pull Request #9 · homebaseio/homebase-react · GitHub
[go: up one dir, main page]

Skip to content

Reduce bundle size #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
10000
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- run: yarn install --frozen-lockfile

- run: yarn shadow-cljs compile npm-dist
- run: yarn shadow-cljs release npm
- run: yarn shadow-cljs compile test

- run: node out/node-tests.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dist/
/src/js_gen/tests

package-lock.json
report.html
pom.xml
pom.xml.asc
*.iml
Expand Down
26 changes: 26 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
node_modules/
public/js
out/

/target
/checkouts
/src/gen
/src/js_gen/tests

package-lock.json
report.html
pom.xml
pom.xml.asc
*.iml
*.jar
*.log
*.orig
.shadow-cljs
.idea
.lein-*
.nrepl-*
.DS_Store
.calva

.hgignore
.hg/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## v0.0.1
- React component to provide a declarative relational DB with minimal fuss.
- React hooks for transact, query and find one entity.
- Make Datascript's syntax more JS and React friendly.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Homebase React

[![CI](https://github.com/homebaseio/homebase-react/workflows/CI/badge.svg)](https://github.com/homebaseio/homebase-react/actions?query=workflow%3ACI)
[![NPM Version](https://badge.fury.io/js/homebase-react.svg)](https://badge.fury.io/js/homebase-react)
[![NPM Version](https://img.shields.io/npm/v/homebase-react)](https://www.npmjs.com/package/homebase-react)
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/homebase-react)](https://www.npmjs.com/package/homebase-react)
[![License](https://img.shields.io/github/license/homebaseio/homebase-react.svg)](LICENSE)


> The graph database for delightful React state management
*The graph database for delightful React state management*

## Installation

Expand Down Expand Up @@ -154,7 +154,7 @@ todos

```bash
yarn install
yarn shadow-cljs watch :dev
yarn dev
```

Open http://localhost:3000
Expand Down
2 changes: 1 addition & 1 deletion js/tests/benchmarks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import Enzyme, { mount } from 'enzyme';
import Benchmark from 'react-component-benchmark';
import Adapter from "enzyme-adapter-react-16";
import { HomebaseProvider, useTransact, useEntity } from '../../dist/homebase.react';
import { HomebaseProvider, useTransact, useEntity } from '../../dist/js/homebase.react';

const config = {
initialData: [{
Expand Down
50 changes: 32 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
"version": "0.0.1",
"license": "MIT",
"homepage": "https://github.com/homebaseio/homebase-react",
"repository": {
"type": "git",
"url": "git+https://github.com/homebaseio/homebase-react.git"
"main": "./dist/js/homebase.react.js",
"scripts": {
"dev": "shadow-cljs watch dev",
"build": "rm -rf dist && shadow-cljs release npm",
"build:dev": "rm -rf dist && shadow-cljs compile npm",
"test:js": "yarn build && jest js/tests",
"test:js:dev": "yarn build:dev && jest js/tests",
"test:cljs": "shadow-cljs compile test && node out/node-tests.js",
"test": "yarn test:cljs && yarn test:js",
"test:dev": "yarn test:cljs && yarn test:js:dev",
"report": "rm -rf dist && shadow-cljs run shadow.cljs.build-report npm report.html"
},
"dependencies": {
"react": "16.14.0"
},
"keywords": [
"react",
"database",
"datalog",
"state",
"graph"
],
"main": "./dist/homebase.react.js",
"devDependencies": {
"@babel/cli": "7.11.6",
"@babel/core": "7.11.6",
Expand All @@ -28,19 +31,30 @@
"highlight.js": "10.2.1",
"jest": "26.6.0",
"marked": "1.2.0",
"react": "16.14.0",
"react-component-benchmark": "0.0.4",
"react-dom": "16.14.0",
"shadow-cljs": "2.11.4"
},
"dependencies": {},
"keywords": [
"react",
"relational",
"database",
"datalog",
"state",
"graph"
],
"repository": {
"type": "git",
"url": "git+https://github.com/homebaseio/homebase-react.git"
},
"bugs": {
"url": "https://github.com/homebaseio/homebase-react/issues"
},
"scripts": {
"test-js": "shadow-cljs compile npm-dist && jest js/tests",
"test-cljs": "shadow-cljs compile test && node out/node-tests.js",
"test": "yarn test-cljs && yarn test-js"
"publishConfig": {
"registry": 2364 "https://npm.pkg.github.com/"
},
"author": ""
"author": "Chris Smothers <chris@homebase.io> (https://homebase.io)",
"contributors": [
"JB Rubinovitz <jb@homebase.io> (https://homebase.io)"
]
}
12 changes: 6 additions & 6 deletions
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
:output-to "out/node-tests.js"
:ns-regexp "-test$"
:autorun false}
:npm-dist {:target :npm-module
:output-dir "dist"
:output-to "dist/lib.js"
:entries [homebase.react]
:compiler-options {:optimizations :advanced
:source-map false}}}}
:npm {:target :npm-module
:output-dir "dist/js"
:entries [homebase.react]
:compiler-options {:optimizations :advanced
:output-wrapper false
:source-map false}}}}
12 changes: 6 additions & 6 deletions src/homebase/js.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@


(defn humanize-transact-error [error]
(condp re-find (.-message error)
(condp re-find (goog.object/get error "message")
#"\[object Object\] is not ISeqable"
"Expected an array of transactions.
\nFor example: transact([
Expand All @@ -192,7 +192,7 @@
"Expected a numerical id.
\nFor example: transact([['retractEntity', 123]])
"
(.-message error)))
(goog.object/get error "message")))

(defn transact! [conn txs]
(try
Expand All @@ -202,12 +202,12 @@


(defn humanize-entity-error [error]
(condp re-find (.-message error)
(condp re-find (goog.object/get error "message")
#"Lookup ref attribute should be marked as :db/unique: \[:([\w-]+)/([\w-]+) ((?!\]).+)\]"
:>> (fn [[_ nmspc attr v]]
(str "The `" nmspc "." attr "` attribute should be marked as unique if you want to lookup entities by it."
"\n\nAdd this to your config: { schema: { " nmspc ": { " attr ": { unique: 'identity' }}}\n"))
(.-message error)))
(goog.object/get error "message")))

(defn entity [conn lookup]
(try
Expand All @@ -226,7 +226,7 @@ For example: query({
")))

(defn humanize-q-error [error]
(condp re-find (.-message error)
(condp re-find (goog.object/get error "message")
#"Query should be a vector or a map"
(str "Expected query to be in the form of an object or datalog string."
(example-js-query))
Expand All @@ -245,7 +245,7 @@ For example: query({
:>> (fn [[_ v]]
(str "Expected $where clause to be a nested object, not " v "."
(example-js-query)))
(.-message error)))
(goog.object/get error "message")))

(defn q [query conn & args]
(try
Expand Down
21 changes: 11 additions & 10 deletions src/homebase/react.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
(catch js/Error e
(throw
(js/Error
(str (.-message e) "\n"
(some->> (.-stack e)
(str (goog.object/get e "message") "\n"
(some->> (goog.object/get e "stack")
(re-find (re-pattern (str hook-name ".*\\n(.*)\\n?")))
(second)
(clojure.string/trim))))))))

(defonce homebase-context (react/createContext))
(defonce ^:export homebase-context (react/createContext))

(def base-schema
{:db/ident {:db/unique :db.unique/identity}})

(defn ^:export HomebaseProvider [props]
(let [config (.-config props)
conn (d/create-conn (if (.-schema config)
(merge (hbjs/js->schema (.-schema config)) base-schema)
(let [conn (d/create-conn (if-let [schema (goog.object/getValueByKeys props #js ["config" "schema"])]
(merge (hbjs/js->schema schema) base-schema)
base-schema))]
(when (.-initialData config) (hbjs/transact! conn (.-initialData config)))
(when-let [tx (goog.object/getValueByKeys props #js ["config" "initialData"])]
(hbjs/transact! conn tx))
(react/createElement
(.-Provider homebase-context) #js {:value conn}
(.-children props))))
(goog.object/get homebase-context "Provider")
#js {:value conn}
(goog.object/get props "children"))))

(defn ^:export useEntity [lookup]
(let [conn (react/useContext homebase-context)
Expand Down Expand Up @@ -58,4 +59,4 @@
(defn ^:export useTransact []
(let [conn (react/useContext homebase-context)
transact (fn transact [txs] (try-hook "useTransact" #(hbjs/transact! conn txs)))]
[transact]))
[transact]))
0