Reusable React environment and components for creating visualization engines.
GPL-3.0 License
Bot releases are hidden (Show)
Published by davelandry about 4 years ago
This release of canon-core contains two substantial 🔥 BREAKING 🔥 changes related to redux and database connections. Please read these release notes to assist in upgrading from a previous version of canon-core.
All redux setup has been moved to a new location: app/store/index.js
. This file is expected to have 3 named exports, and at it's minimum, should look like this:
/**
* This object will be used to pre-populate the redux store with any
* static values you may need.
*/
export const initialState = {};
/**
* This array can contain redux middlewares that will be used in the
* redux store. The loggerMiddleware is provided as an example.
*/
export const middleware = [];
/**
* This object should contain reducers to be combined with the internal
* default canon reducers.
*/
export const reducers = {};
app/store/index.js
file with the contents from above.app/reducers/index.jsx
to the reducers
variable in this new file and delete the old app/reducers/index.jsx
file.app/reducers/
to new app/store/reducers/
folder and delete the old app/reducers/
folder.app/store.js
to the initialState
variable in this new app/store/index.js
file and delete the old app/store.js
file../canon.js
file to the middleware
Array in this new app/store/index.js
file. In ./canon.js
, the middleware was enabled with a function where the user had to add the middleware needed to a list of core middleware, and return applyMiddleware(...middlewares)
. The new way only needs an array of the user defined middleware; the internals will do the combination with the core middleware and the call to applyMiddleware
.This release of canon-core allows sites to connect to multiple separate databases, if desired (for example, hosting the users
table in a completely different database than the CMS content tables). In order to do this, database connections now need to be defined explicitly in the ./canon.js
file.
In it's simplest form, if you have a custom database table on your site located at ./db/customTable.js
, then your config in ./canon.js
would look like this:
module.exports = {
...,
db: [
{
host: process.env.CANON_DB_HOST,
name: process.env.CANON_DB_NAME,
user: process.env.CANON_DB_USER,
pass: process.env.CANON_DB_PW,
tables: [
// using require.resolve enables canon-core to reload the models
// if the file is edited while the server is running on development mode
require.resolve("./db/customTable.js")
]
}
]
};
Another new feature we are introducing is allowing connection strings for database connections, so instead of managing separate environment variables for host
, name
, user
, and pass
, you can construct a connection string and supply it to connection
:
const {CANON_DB_USER, CANON_DB_PASS, CANON_DB_HOST, CANON_DB_NAME} = process.env;
const dbConnection = `postgresql://${CANON_DB_USER}:${CANON_DB_PASS}@${CANON_DB_HOST}:5432/${CANON_DB_NAME}`;
module.exports = {
...,
db: [
{
connection: dbConnection
tables: [
require.resolve("./db/customTable.js")
]
}
]
};
Notice that the db
value is an Array? This is what allows for multiple databases connections to be set up. Additionally, all canon plugins (like canon-cms) will now be exporting a models
Object containing their internal tables that will need to be explicitly linked here as well. Let's say you have a database on a different server that you want to use to host the CMS tables, and you've stored the connection string in the environment as CANON_CMS_DB
:
const {CANON_DB_USER, CANON_DB_PASS, CANON_DB_HOST, CANON_DB_NAME} = process.env;
const dbConnection = `postgresql://${CANON_DB_USER}:${CANON_DB_PASS}@${CANON_DB_HOST}:5432/${CANON_DB_NAME}`;
module.exports = {
...,
db: [
{
connection: process.env.CANON_CMS_DB,
tables: [
require("@datawheel/canon-cms/models")
]
}
{
connection: dbConnection
tables: [
require.resolve("./db/customTable.js")
]
}
]
};
This new setup method also allows additionally configuration to be performed on the Sequelize instance used to connect to the database. Full documentation can be found here.
Note: because the connections are explicitly defined, the environment variable names for databases can now be anything you want!
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry about 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago
Published by davelandry over 4 years ago