0.9.17 • Published 5 years ago

redux-db v0.9.17

Weekly downloads
136
License
MIT
Repository
github
Last release
5 years ago

redux-db

NPM downloads NPM package

redux-db provides a normalized redux store and easy object management.

Why

Having a normalized state is a good strategy if your data is nested in different ways. The redux documentation has a nice explanation here.

How

import db from "./schema";
 export const dbReducer = db.combineReducers(
    (session, action) => {
        const { BlogPost, Comment, User } = session;
         switch (action.type) {
            case "POSTS_FETCH_DONE":
            case "POST_FETCH_DONE":
            case "POST_UPDATE":
            case "POST_INSERT":
                // all these actions may be handled using just one statement.
                // the upsert method accepts both single objects and arrays.
                // the payload is automatically normalized and related tables are also updated.
                 BlogPost.upsert(action.payload);
                break;
             case "POST_DELETE": {
                const { id } = action.payload;
                const post = BlogPost.get(id);
                 post.comments.delete(); // Could be skipped if cascading deletes are defined.
                post.delete();
                 // or just, BlogPost.delete( id );
                break;
            }
            case "COMMENT_UPDATE":
            case "COMMENT_INSERT": {
                // assuming payload contains {id,post,author}
                const { post } = action.payload;
                 BlogPost.get(post).comments.add(action.payload);
                // or just, Comment.upsert(action.payload);
                break;
            }
            case "COMMENT_DELETE": {
                const { id } = action.payload;
                Comment.delete(id);
                break;
            }
        }
    }
);

Documentation

Head over to http://redux-db.readthedocs.io.

Examples

You will find an extensive example using redux-db to create a basic "todo" app in the /examples folder.

Contact / feedback

Feel free to create issues and PR's.

Dependencies

  • none

Performance & size

redux-db uses internal indexes to speed up lookups and is quite fast at the current state. However, optimizing performance and build size is a high priority forward. Current size is small, only ~5K minified and gzipped.

Credits

This project is inspired by libraries such as normalizr and redux-orm. redux-db is however a complete rewrite and only lends it's basic consepts.

Changelog

v0.9.0

  • Bugfixes and improvements

v0.8.0

  • Added support for providing a custom model factory.
  • BREAKING CHANGE: some exported interfaces are renamed
    • Record => TableRecord
    • RecordSet => TableRecordSet

v0.7.0

  • Added support for PK fields to also reference foreign tables.
  • Improved error handling for some cases.
  • BREAKING CHANGE: the field type "FK" is removed. Instead it is implied from the usage of the "references" definition.
  • Docs is updated to latest changes and features.

v0.6.0

  • Added support for one 2 one relationships
  • Added support for cascading deletes
  • Improved typings
  • Minor optimizations
1.1.0-beta.0

5 years ago

1.0.0-beta.5

5 years ago

1.0.0-beta.3

5 years ago

1.0.0-beta.2

5 years ago

1.0.0-beta.1

5 years ago

1.0.0-beta.0

5 years ago

0.9.17

6 years ago

0.9.16

6 years ago

0.9.15

6 years ago

0.9.14

6 years ago

0.9.13

6 years ago

0.9.12

6 years ago

0.9.11

6 years ago

0.9.10

6 years ago

0.9.9

6 years ago

0.9.8

6 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.7

7 years ago

0.7.6

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.3.27

7 years ago

0.3.26

7 years ago

0.3.25

7 years ago

0.3.23

7 years ago

0.3.22

7 years ago

0.3.21

7 years ago

0.3.20

7 years ago

0.3.19

7 years ago

0.3.18

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0-18

7 years ago

0.0.0-17

7 years ago

0.0.0-16

7 years ago

0.0.0-15

7 years ago

0.0.0-14

7 years ago

0.0.0-13

7 years ago

0.0.0-12

7 years ago

0.0.0-11

7 years ago

0.0.0-10

7 years ago

0.0.0-9

7 years ago

0.0.0-8

7 years ago

0.0.0-7

7 years ago

0.0.0-6

7 years ago

0.0.0-5

7 years ago

0.0.0-4

7 years ago

0.0.0-3

7 years ago

0.0.0-2

7 years ago

1.0.2-2

7 years ago

1.0.2-1

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago