Skip to content

Commit

Permalink
Update dependencies, add support for Map and Set
Browse files Browse the repository at this point in the history
  • Loading branch information
aslilac committed Apr 25, 2020
1 parent ff7bfdc commit 3f2f1df
Show file tree
Hide file tree
Showing 10 changed files with 2,963 additions and 1,796 deletions.
76 changes: 38 additions & 38 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
version: 2
jobs:
build:
working_directory: ~/electron-redux
docker:
- image: circleci/node:8-browsers
steps:
- checkout
- restore_cache:
keys:
- electron-redux2-{{ .Branch }}
- electron-redux2-
- run:
name: Install Dependencies
command: yarn && ./node_modules/.bin/lerna bootstrap
- save_cache:
key: electron-redux2-{{ .Branch }}
paths:
- "~/.cache/yarn"
- "~/electron-redux/node_modules"
- "~/electron-redux/packages/electron-redux/node_modules"
- "~/electron-redux/packages/electron-redux-e2e/node_modules"
- run:
name: Update yarn lockfile
command: ./node_modules/.bin/greenkeeper-lockfile-update
- run:
name: Compile Assets
command: ./node_modules/.bin/lerna run build
- run:
name: Run Tests
command: yarn test
- run:
name: Upload yarn lockfile
command: ./node_modules/.bin/greenkeeper-lockfile-upload
- store_artifacts:
path: ~/electron-redux/packages/electron-redux/dist
destination: dist
- store_artifacts:
path: ~/electron-redux/packages/electron-redux/node_modules/coverage
destination: coverage
build:
working_directory: ~/electron-redux
docker:
- image: circleci/node:12-browsers
steps:
- checkout
- restore_cache:
keys:
- electron-redux2-{{ .Branch }}
- electron-redux2-
- run:
name: Install Dependencies
command: yarn && ./node_modules/.bin/lerna bootstrap
- save_cache:
key: electron-redux2-{{ .Branch }}
paths:
- "~/.cache/yarn"
- "~/electron-redux/node_modules"
- "~/electron-redux/packages/electron-redux/node_modules"
- "~/electron-redux/packages/electron-redux-e2e/node_modules"
- run:
name: Update yarn lockfile
command: ./node_modules/.bin/greenkeeper-lockfile-update
- run:
name: Compile Assets
command: ./node_modules/.bin/lerna run build
- run:
name: Run Tests
command: yarn test
- run:
name: Upload yarn lockfile
command: ./node_modules/.bin/greenkeeper-lockfile-upload
- store_artifacts:
path: ~/electron-redux/packages/electron-redux/dist
destination: dist
- store_artifacts:
path: ~/electron-redux/packages/electron-redux/node_modules/coverage
destination: coverage
56 changes: 26 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
{
"private": true,
"name": "electron-redux",
"version": "1.4.0",
"description": "Using redux in electron",
"main": "index.js",
"repository": "https://github.com/hardchor/electron-redux",
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://burgiblog.com)",
"license": "MIT",
"devDependencies": {
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.2.0",
"husky": "^2.2.0",
"lerna": "^3.13.4",
"lint-staged": "^9.2.1",
"prettier-eslint-cli": "^5.0.0"
},
"scripts": {
"test": "lerna run test",
"precommit": "lint-staged"
},
"workspaces": [
"packages/*"
],
"lint-staged": {
"*.{js,jsx,css,md}": [
"prettier-eslint --single-quote --trailing-comma=all --print-width=100 --write",
"git add"
]
}
"private": true,
"repository": "https://github.com/hardchor/electron-redux",
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://burgiblog.com)",
"license": "MIT",
"devDependencies": {
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"husky": "^2.2.0",
"lerna": "^3.13.4",
"lint-staged": "^9.2.1",
"prettier-eslint-cli": "^5.0.0"
},
"scripts": {
"test": "lerna run test",
"precommit": "lint-staged"
},
"workspaces": [
"packages/*"
],
"lint-staged": {
"*.{js,jsx,css,md}": [
"prettier-eslint --single-quote --trailing-comma=all --print-width=100 --write",
"git add"
]
}
}
22 changes: 15 additions & 7 deletions packages/electron-redux-e2e/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('electron-redux');
const reducers = require('./reducers');

const store = createStore(reducers, 0, applyMiddleware(triggerAlias, forwardToRenderer));
const store = createStore(reducers, applyMiddleware(triggerAlias, forwardToRenderer));

replayActionMain(store);

Expand All @@ -23,14 +23,22 @@ let mainWindow;

function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({ width: 800, height: 600 });
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}));
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true,
}),
);

// Open the DevTools.
// mainWindow.webContents.openDevTools()
Expand Down
14 changes: 8 additions & 6 deletions packages/electron-redux-e2e/app/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
function counter(state, action) {
if (typeof state === 'undefined') {
return 0;
}
const init = () => ({
count: 0,
testMap: new Map([['hello', 'friend'], ['name', 'mckayla']]),
testSet: new Set([1, 2, 3, 4, 5]),
});

function counter(state = init(), action) {
switch (action.type) {
case 'INCREMENT':
return state + 1;
return { ...state, count: state.count + 1 };
case 'DECREMENT':
return state - 1;
return { ...state, count: state.count - 1 };
default:
return state;
}
Expand Down
9 changes: 7 additions & 2 deletions packages/electron-redux-e2e/app/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ replayActionRenderer(store);
const valueEl = document.getElementById('value');

function render() {
valueEl.innerHTML = store.getState().toString();
console.log(store.getState());
valueEl.innerHTML = store.getState().count.toString();
}

render();
Expand All @@ -31,5 +32,9 @@ document.getElementById('decrement').addEventListener('click', () => {
});

document.getElementById('incrementAliased').addEventListener('click', () => {
store.dispatch(createAliasedAction('INCREMENT_ALIASED', () => ({ type: 'INCREMENT' }))());
store.dispatch(
createAliasedAction('INCREMENT_ALIASED', () => ({
type: 'INCREMENT',
}))(),
);
});
50 changes: 25 additions & 25 deletions packages/electron-redux-e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "electron-redux-e2e",
"version": "1.4.0",
"description": "The end-to-end tests for electron-redux",
"main": "app/main.js",
"repository": "https://github.com/hardchor/electron-redux/tree/master/packages/electron-redux-e2e",
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://burgiblog.com)",
"license": "MIT",
"private": true,
"dependencies": {
"electron": "^1.7.9",
"electron-redux": "^1.4.0",
"redux": "^4.0.1"
},
"scripts": {
"start": "electron .",
"test": "jest .",
"snyk-protect": "snyk protect",
"prepublish": "yarn snyk-protect"
},
"devDependencies": {
"jest": "^21.2.1",
"snyk": "^1.189.0",
"spectron": "^3.7.2"
},
"snyk": true
"name": "electron-redux-e2e",
"version": "2.0.0",
"description": "The end-to-end tests for electron-redux",
"main": "app/main.js",
"repository": "https://github.com/hardchor/electron-redux/tree/master/packages/electron-redux-e2e",
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://burgiblog.com)",
"license": "MIT",
"private": true,
"dependencies": {
"electron": "^8.0.0",
"electron-redux": "^2.0.0",
"redux": "^4.0.1"
},
"scripts": {
"start": "electron .",
"test": "jest .",
"snyk-protect": "snyk protect",
"prepublish": "yarn snyk-protect"
},
"devDependencies": {
"jest": "^25.0.0",
"snyk": "^1.189.0",
"spectron": "^10.0.0"
},
"snyk": true
}
99 changes: 48 additions & 51 deletions packages/electron-redux/package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
{
"name": "electron-redux",
"version": "1.4.0",
"description": "Use redux in the main and browser process in electron",
"main": "dist/index.js",
"files": [
"dist/**"
],
"scripts": {
"test": "rm -rf coverage && jest --coverage",
"lint": "eslint 'src/**/*'",
"build": "rm -rf dist && babel src --out-dir dist",
"prepare": "yarn build",
"prepush": "yarn test && yarn build",
"snyk-protect": "snyk protect",
"prepublish": "yarn snyk-protect"
},
"keywords": [
"electron",
"redux",
"react",
"desktop"
],
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://www.burgiblog.com)",
"repository": {
"type": "git",
"url": "https://github.com/hardchor/electron-redux.git"
},
"homepage": "https://github.com/hardchor/electron-redux/tree/master/packages/electron-redux",
"bugs": "https://github.com/hardchor/electron-redux/issues",
"license": "MIT",
"dependencies": {
"debug": "^3.0.0",
"flux-standard-action": "^2.0.0",
"redux": "^4.0.1"
},
"peerDependencies": {
"redux": "^4.0.1"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.34",
"@babel/core": "^7.0.0-beta.34",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-beta.34",
"@babel/preset-env": "^7.0.0-beta.34",
"babel-core": "^7.0.0-0",
"babel-eslint": "^10.0.1",
"babel-jest": "^21.2.0",
"greenkeeper-lockfile": "^1.12.0",
"jest": "^21.2.1",
"snyk": "^1.189.0"
},
"snyk": true
"name": "electron-redux",
"version": "2.0.0",
"description": "Use redux in the main and browser process in electron",
"main": "dist/index.js",
"files": [
"dist/**"
],
"scripts": {
"test": "rm -rf coverage && jest --coverage",
"lint": "eslint 'src/**/*'",
"build": "rm -rf dist && babel src --out-dir dist",
"prepare": "yarn build",
"prepush": "yarn test && yarn build",
"snyk-protect": "snyk protect",
"prepublish": "yarn snyk-protect"
},
"keywords": [
"electron",
"redux",
"react",
"desktop"
],
"author": "Burkhard Reffeling <burkhard.reffeling@gmail.com> (http://www.burgiblog.com)",
"repository": {
"type": "git",
"url": "https://github.com/hardchor/electron-redux.git"
},
"homepage": "https://github.com/hardchor/electron-redux/tree/master/packages/electron-redux",
"bugs": "https://github.com/hardchor/electron-redux/issues",
"license": "MIT",
"dependencies": {
"debug": "^4.0.0",
"flux-standard-action": "^2.0.0"
},
"peerDependencies": {
"redux": "^4.0.1"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^25.0.0",
"jest": "^25.0.0",
"snyk": "^1.189.0"
},
"snyk": true
}
16 changes: 14 additions & 2 deletions packages/electron-redux/src/helpers/getInitialStateRenderer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { remote } from 'electron';

const hydrate = (key, value) => {
if (value?.__hydrate_type === '__hydrate_map') {
return new Map(Object.entries(value).filter(([key]) => key !== '__hydrate_type'));
} else if (value?.__hydrate_type === '__hydrate_set') {
return new Set(value.items);
}

return value;
};

export default function getInitialStateRenderer() {
const getReduxState = remote.getGlobal('getReduxState');
if (!getReduxState) {
throw new Error('Could not find reduxState global in main process, did you forget to call replayActionMain?');
throw new Error(
'Could not find reduxState global in main process, did you forget to call replayActionMain?',
);
}
return JSON.parse(getReduxState());
return JSON.parse(getReduxState(), hydrate);
}
Loading

0 comments on commit 3f2f1df

Please sign in to comment.