Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
156b2ce
Refactoring to one top-level package
martinmsm Apr 26, 2020
d5ab640
Publish
martinmsm Apr 26, 2020
9b41384
Export all the things
martinmsm Apr 26, 2020
0126883
Publish
martinmsm Apr 26, 2020
3397f80
Export states with hooks
martinmsm Apr 26, 2020
cc76b45
Publish
martinmsm Apr 26, 2020
aafdf49
Add makeClientModel helper
martinmsm Apr 27, 2020
016785b
Publish
martinmsm Apr 27, 2020
658ce7e
Add init method for init'ing Firebase
martinmsm Apr 30, 2020
cf015e8
Return the value from init
martinmsm Apr 30, 2020
88dd41d
Publish
martinmsm Apr 30, 2020
fc3c22f
Make firebase a dev dep
martinmsm Apr 30, 2020
27bb7cc
Publish
martinmsm Apr 30, 2020
7c3e6fc
Adding query params to loadCollection
martinmsm May 2, 2020
d826cf6
Adding FirekitAuth provider and hook
martinmsm May 2, 2020
d320078
Renaming FirekitAuth provider
martinmsm May 2, 2020
a2b3bec
Add yup as peer dep
martinmsm May 2, 2020
bfd742c
Add FirekitOrganizationProvider
martinmsm May 2, 2020
896d2ae
Publish
martinmsm May 2, 2020
90c7996
Export new Providers at top level
martinmsm May 2, 2020
80c8096
Publish
martinmsm May 2, 2020
f581ab3
Moving more export to top level
martinmsm May 2, 2020
746a5b7
Publish
martinmsm May 2, 2020
1a85151
Fixing copy/paste mistakes
martinmsm May 2, 2020
0ae9a5b
Publish
martinmsm May 2, 2020
720a644
Added linting
martinmsm May 2, 2020
164a66c
Fix linting errors
martinmsm May 2, 2020
fc55d18
Publish
martinmsm May 2, 2020
266ce6f
Lerna mishap.. bumping
martinmsm May 2, 2020
61d04ac
Publish
martinmsm May 2, 2020
3273010
Bump websocket-extensions from 0.1.3 to 0.1.4 in /packages/api
dependabot[bot] Jun 8, 2020
a124abc
DX Improvements
Jun 26, 2020
7f50c10
Windows Line Changes
Jun 26, 2020
0ecc875
Publish
Jun 26, 2020
3c0a679
BUMP
Jun 26, 2020
92b5a86
Publish
Jun 26, 2020
404443c
Add touched to model
Jun 27, 2020
36e9373
Publish
Jun 27, 2020
d0b191a
Tweak some test settings
Jun 27, 2020
52c6b1f
Publish
Jun 27, 2020
7a19596
Expose reload to useModel hook
Jun 28, 2020
90dd768
Publish
Jun 28, 2020
c5163cb
Expose result of save to hook
Jun 29, 2020
056b5cb
Always return value
Jun 29, 2020
deecef7
Publish
Jun 29, 2020
29d60af
Send isFetching to useModel
Aug 23, 2020
d11660d
Publish
Aug 23, 2020
c588cdc
Pass all react-query props through
Aug 23, 2020
844120a
Publish
Aug 23, 2020
0357ab2
Publish
Aug 23, 2020
7a57b6b
Allow `id` property
martinmsm Feb 16, 2021
450e4cc
Forward slashes instead of back slashes
martinmsm Feb 16, 2021
489a3f2
Publish
martinmsm Feb 16, 2021
466e69f
Fixing npm audit issues
martinmsm Feb 16, 2021
99f4346
Publish
martinmsm Feb 16, 2021
2a1a638
Check for undefined in where clause
martinmsm Feb 17, 2021
516c9a8
Publish
martinmsm Feb 17, 2021
f2e6fa4
Use debug instead of error to minimize visual impact in console
martinmsm Feb 17, 2021
c260ee2
Publish
martinmsm Feb 17, 2021
f68a58a
Better handling of bad where clause.
martinmsm Feb 17, 2021
ff1bb94
Publish
martinmsm Feb 17, 2021
0c2e487
Bump
martinmsm Feb 17, 2021
87efc5b
Publish
martinmsm Feb 17, 2021
d2cb098
Don't catch and re-throw this error
martinmsm Feb 22, 2021
f75b6d0
Collection is now contant
martinmsm Feb 22, 2021
7bde624
No need to instantiate early
martinmsm Feb 22, 2021
c202943
Publish
martinmsm Feb 22, 2021
a3f235a
Allow order to be an array
martinmsm Feb 27, 2021
c59ae43
Publish
martinmsm Feb 27, 2021
004958d
Don't allow null values in cache keys
martinmsm Mar 4, 2021
4995d46
Publish
martinmsm Mar 4, 2021
f906433
Oops. Can't set limit to zero
martinmsm Mar 4, 2021
4bf343e
Publish
martinmsm Mar 4, 2021
92c17b8
Merge pull request #1 from michael-martin-al/dependabot/npm_and_yarn/…
Aug 26, 2022
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
46 changes: 46 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const path = require('path')

module.exports = {
"extends": [
"airbnb-base",
"plugin:prettier/recommended",
],
"globals": {
"window": true,
"document": true,
"it": true,
"FileReader": true
},
"env": {
"browser": true,
"jest": true,
"es6": true,
"node": true
},
"parser": 'babel-eslint',
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"ignorePatterns": [
"**/node_modules/**",
"**/lib",
"**/lib/**/*.js"
],
"rules": {
"import/prefer-default-export": "off",
"import/no-extraneous-dependencies": "off",
"no-unused-vars": "warn"
},
"settings": {
"import/resolver": {
"node": {
"extensions": ['.js', '.jsx', '.test.js'],
"moduleDirectory": [
"node_modules",
"src"
]
}
}
}
};
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.cache
*.DS_Store
node_modules
node_modules/*
dist/*
coverage
lib
.envrc
*.log
**/node_modules
**/lib
9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
printWidth: 80,
trailingComma: "all",
tabWidth: 2,
semi: false,
arrowParens: "always",
singleQuote: true,
jsxSingleQuote: false
};
Empty file added README.md
Empty file.
20 changes: 20 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"presets": [
"@babel/react",
[
"@babel/env",
{
"targets": {
"browsers": "last 2 versions",
"node": "12.16.2"
}
}
]
],
"env": {
"build": {
"ignore": []
}
},
"ignore": ["node_modules"]
}
127 changes: 127 additions & 0 deletions docs/async-form.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# AsyncForm
A Compound Collection of Components for handling async forms in a web app

## FormLoadError
It should display an error message to the user.
Renders its children when an error occurs while initially loading data. Attaches the `error` prop to all children before rendering.

## FormError
It should display an error message to the user.
Renders its children when an error occurs while performing a form action. Attaches the `error` prop to all children before rendering.

## FormLoading
It should show a spinner or a label indicating the form is loading.
Renders its children when the form is busy with an async action such as loading, saving, etc.

## FormContent
It should contain the body of the form, including any fields, labels, etc.
Renders its children when the form's state is idle, error, loadSuccess, updating, updateSuccess or deleting.

## FormActions
It should render buttons or other UI elements to allow user to perform Save, Delete actions
Renders its children under the same conditions as <FormContent />.
Attaches `state`, `handleDelete`, and `handleSave` props to all children.

## FormDeleteSuccess
It should show a message informing the user that their delete operation succeeded.
Renders its children when the state is deleteSuccess.

## AsyncForm
Renders various states of a form based on the UI state of an async action(s)

### Props
- **state**: the state value from `useModel` hook
- **error**: the error value from `useModel` hook
- **handleSave**: the function returned from the `useModel` hook
- **handleDelete**: the function returned form the `useModel` hook
- **afterUpdate**: the function to fire after a successful update operation
- **afterDelete**: the function to fire after a successful delete operation
- **children**: any combination of the above Components + any other React components to render an input form to the user

## Example
```javascript
import React from 'react'
import {
AsyncForm,
FormActions,
FormContent,
FormError,
FormInitError,
FormInitializing,
FormLoading
} from './components/async-form'
import useWidget from '../models/use-widget'

function WidgetFormError({ error }) {
return (
<p>{error.message}</p>
)
}

function WidgetFormActions({
handleSave,
handleDelete,
state
}) {
return (
<div>
<button type="submit" disabled={state === 'loading'}>Submit</button>
<button type="button" onClick={handleSave} disabled={state === 'loading'}>Save</button>
<button type="button" onClick={handleDelete} disabled={state === 'deleting'}>Delete</button>
</div>
)
}

export default function WidgetForm({ id }) {
const {
model: widget,
handleAttributeChange,
handleSave,
handleDelete,
state,
error,
} = useWidget(id, { staleTime: 10000 })

return (
<AsyncForm
state={state}
error={error}
handleSave={handleSave}
handleDelete={handleDelete}
onUpdate={() => {
alert('Just Updated!')
}}
>
<FormInitializing>
<p>Initializing...</p>
</FormInitializing>

<FormInitError>
<p>Init Error!</p>
</FormInitError>

<FormLoading>
<p>Loading...</p>
</FormLoading>

<FormError>
<WidgetFormError />
</FormError>

<FormContent>
{widget && widget.$error && widget.$error.map((e) => {
return <p key={e}>{e}</p>
})}
{widget && JSON.stringify(widget.$object)}
<div><input type="text" name="name" onChange={handleAttributeChange} value={widget ? widget.name.$value : ''} /></div>
<div><input type="date" name="created" onChange={handleAttributeChange} value={widget ? widget.created.$value : ''} /></div>
<div><input type="number" name="quantity" onChange={handleAttributeChange} value={widget ? widget.quantity.$value : 0} /></div>
</FormContent>

<FormActions>
<WidgetFormActions />
</FormActions>
</AsyncForm>
)
}
```
Empty file added docs/async-list.md
Empty file.
Empty file added docs/async-view.md
Empty file.
115 changes: 115 additions & 0 deletions docs/client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Client Interface
## Purpose
Make calls to a service to fetch/update/create/delete data, usually asynchronously

---

## Exports

### load : Function
**Returns** Async Function with a `key` property

a function that accepts a Model() function as its first argument and returns an async function which will fetch a single resource. The async function must also have a property called `key` that contains a string or array which uniquely identifies the data that will be loaded. This `key` value will be used to identify the returned resource in cache.

```javascript
export function load({
Model, /* A Model() creator */
...
/* any additional config values necessary for target backend */
}) {

async function loader() {
/* 1. do some loading */
/* 2. Use Model creator function to create a Model instance */
/* 3. Return the Model instance */
}

loader.key = `some unique id` // an unique array or string identifier

return loader
}
```

---

### loadCollection
**Returns** Async Function with a `key` property

a function that accepts a Model() function as its first argument and returns an async function which will fetch a collection of resources. The async function must also have a property called `key` that contains a string or array which uniquely identifies the data that will be loaded. This `key` value will be used to identify the returned resource in cache.

```javascript
export function loadCollection({
Model, /* A Model() creator */
...
/* any additional config values necessary for target backend */
}) {

async function loader() {
/* 1. do some loading */
/* 2. map through the results from the backend */
/* 3. Use Model creator function to create an array of Models */
/* 4. Return the Models[] array */
}

loader.key = `some unique id` // a unique array or string identifier

return loader
}
```
---

### create
**Returns** Promise

an async function that creates a new resource on the target backend

```javascript
export async function create({
model: An instance of a Model with magic $ methods,
...
/* any additional config values necessary for target backend */
}) {
/* check `model.$valid` */
/* throw Error if not valid */
/* Otherwise, do some creating and return promise */
}
```

---

### update
**Returns** Promise

an async function that updates an existing resource on the target backend

```javascript
export async function update({
model: An instance of a Model with magic $ methods,
...
/* any additional config values necessary for target backend */
}) {
/* check `model.$valid` */
/* throw Error if not valid */
/* Otherwise, do some updating and return promise */
}
```

---

### del
**Returns** Promise

an async function that deletes an existing resource on the target backend

```javascript
export async function del({
/* any config values necessary for target backend */
}) {
/* Do some deleting and return promise */
}
```





Loading