Skip to content

Commit

Permalink
Formatted Code and changed from context to redux for active subscript…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
tobicrain committed Oct 17, 2022
1 parent 7510dc4 commit 91eacef
Show file tree
Hide file tree
Showing 27 changed files with 304 additions and 213 deletions.
10 changes: 4 additions & 6 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { NODE_ENV, BABEL_ENV } = process.env
const cjs = NODE_ENV === 'test' || BABEL_ENV === 'commonjs'
const { NODE_ENV, BABEL_ENV } = process.env;
const cjs = NODE_ENV === 'test' || BABEL_ENV === 'commonjs';

module.exports = {
presets: [
Expand Down Expand Up @@ -28,13 +28,11 @@ module.exports = {
'@babel/transform-runtime',
{
useESModules: !cjs,
version: require('./package.json').dependencies[
'@babel/runtime'
]
version: require('./package.json').dependencies['@babel/runtime'],
},
],
].filter(Boolean),
assumptions: {
enumerableModuleMeta: true,
},
}
};
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"bracketSameLine": true,
"trailingComma": "es5"
}
18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
Expand All @@ -7,30 +8,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

## [0.1.5] - 2022-10-10

### Changed

- SDK now uses custom @tobicrain/pocketbase javascript framework

## [0.1.4] - 2022-10-10

### Fixed

- SDK now runs on React and React Native

## [0.1.3] - 2022-10-06

### Changed
- Redux now toggles between localStorage / AsyncStorage

- Redux now toggles between localStorage / AsyncStorage

## [0.1.2] - 2022-10-05

### Changed
- Adjusted Rollup / Babel Config for use in React

- Adjusted Rollup / Babel Config for use in React

## [0.1.1] - 2022-10-04

### Changed

- initialCollections now also "subscribe" instead of just "fetch" content once

## [0.1.0] - 2022-10-03

### Added

- Initial commit

### Changed
- Readme Instructions and so on

- Readme Instructions and so on
72 changes: 56 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
PocketBase React SDK
======================================================================
# PocketBase React SDK

[![Npm package version](https://badgen.net/npm/v/pocketbase-react)](https://npmjs.com/package/pocketbase-react)

Unofficial React SDK (React, React Native, Expo) for interacting with the [PocketBase JS SDK](https://github.com/pocketbase/js-sdk).


- [Installation](#installation)
- [Usage](#usage)
- [Caveats](#caveats)
- [Development](#development)


## Installation

### React, React Native or Expo


```sh
# Using npm
npm install pocketbase-react --save

#Using yarn
yarn add pocketbase-react
```

```tsx
import { Pocketbase } from 'pocketbase-react';
```

---

> 🔧 React Native / Expo doesn't have native `EventSource` implementation, so in order to use the realtime service you'll need to load a `EventSource` polyfill.
> I recommend [EventSource/eventsource](https://github.com/EventSource/eventsource)
>
> ```sh
> # Using npm
> npm install eventsource --save
>
> # Using yarn
> yarn add eventsource
> ```
> ```js
>
> ```js
> // EventSource.ts
> var Source = require('event-source');
> global.EventSource = Source;
Expand Down Expand Up @@ -68,109 +69,148 @@ const mobileRedirectURL = "expo://..." // for example
```
## Caveats
```tsx
import { useAppContent, useAuth } from "pocketbase-react";
import { useAppContent, useAuth } from 'pocketbase-react';
```
### Records
Reading the records value directly accesses the Redux Store.
The value will be changed automatically by the following actions:
- [Initial Fetch](#initialfetch)
- [Initial Collections](#usage)
- [Subscribe](#subscribe)
- [Refetch](#refetch)
**Without** Initial Fetch
```tsx
// Corresponds to the stored Redux value, simply reads without making further PocketBase requests
const { records } = useAppContent("COLLECTION_NAME_01")
const { records } = useAppContent('COLLECTION_NAME_01');
```
**With** Initial Fetch <a name="initialfetch"></a>
```tsx
// When initializing, the desired table is queried once and updated in Redux, records corresponds to the stored Redux value
const { records } = useAppContent("COLLECTION_NAME_01", true)
const { records } = useAppContent('COLLECTION_NAME_01', true);
```
### Actions
```tsx
const { actions } = useAppContent("COLLECTION_NAME_01")
const { actions } = useAppContent('COLLECTION_NAME_01');
```
> *All following actions are performed on the desired table, in this case -> COLLECTION_NAME_01*
> _All following actions are performed on the desired table, in this case -> COLLECTION_NAME_01_
>
> ⚠️ **All actions will not return anything, they will just modify the Redux value according to their intention**
Subscribe <a name="subscribe"></a>
```tsx
actions.subscribe();
```
Unsubscribe
```tsx
actions.unsubscribe();
```
Refetch <a name="refetch"></a>
```tsx
actions.refetch();
```
Create
```tsx
const object = {};
actions.create(object);
```
Update
```tsx
const id = "SOME_ID";
const id = 'SOME_ID';
const object = {};
actions.update(id, object);
```
DELETE
```tsx
const id = "SOME_ID";
const id = 'SOME_ID';
actions.delete(id);
```
### Auth
```tsx
const { actions } = useAuth()
const { actions } = useAuth();
```
Register with Email <a name="subscribe"></a>
```tsx
await actions.registerWithEmail(email: string, password: string);
```
Sign-In with Email
```tsx
await actions.signInWithEmail(email: string, password: string);
```
Sign-In with Provider
```tsx
await actions.signInWithProvider(provider: string);
```
Submit Provider Result
Submit Provider Result
```tsx
await actions.submitProviderResult(url: string);
```
Sign-Out
```tsx
actions.signOut();
```
Send password reset email
```tsx
await actions.sendPasswordResetEmail(email: string);
```
Send email verification
```tsx
await actions.sendEmailVerification(email: string);
```
Update profile
```tsx
await actions.updateProfile(id: string, record: {});
```
Update profile
```tsx
await actions.updateEmail(email: string);
```
Delete user
```tsx
await actions.deleteUser(id: string);
```
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pocketbase-react",
"version": "0.1.14",
"version": "0.1.15",
"description": "Unofficial React SDK (React, React Native, Expo) for interacting with the PocketBase JS SDK",
"keywords": [
"pocketbase",
Expand Down
24 changes: 12 additions & 12 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import nodeResolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
import nodeResolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';

const env = process.env.NODE_ENV
const env = process.env.NODE_ENV;

const extensions = ['.js', '.ts', '.tsx', '.json']
const extensions = ['.js', '.ts', '.tsx', '.json'];

const config = {
input: 'src/index.ts',
Expand All @@ -17,7 +17,7 @@ const config = {
name: 'PocketbaseReact',
globals: {
react: 'React',
pocketbase: '@tobicrain/pocketbase'
pocketbase: '@tobicrain/pocketbase',
},
},
plugins: [
Expand All @@ -36,7 +36,7 @@ const config = {
}),
commonjs(),
],
}
};

if (env === 'production') {
config.plugins.push(
Expand All @@ -48,7 +48,7 @@ if (env === 'production') {
warnings: false,
},
})
)
);
}

export default config
export default config;
7 changes: 5 additions & 2 deletions src/context/Pocketbase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ export const Pocketbase = (props: PocketbaseProviderProps) => {
<ClientProvider client={client}>
<Provider store={store.store}>
<PersistGate persistor={store.persistor}>
<AuthProvider webRedirectUrl={props.webRedirectUrl} mobileRedirectUrl={props.mobileRedirectUrl} openURL={props.openURL} >
<AuthProvider
webRedirectUrl={props.webRedirectUrl}
mobileRedirectUrl={props.mobileRedirectUrl}
openURL={props.openURL}>
<ContentProvider collections={props.initialCollections}>
{props.children}
</ContentProvider>
</AuthProvider>
</PersistGate>
</Provider>
</ClientProvider>
): null;
) : null;
};
Loading

0 comments on commit 91eacef

Please sign in to comment.