Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with middleware #224

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions packages/diffhtml-components/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const RenderDebounce = new WeakMap();

/**
* @param {Props} defaultProps
* @returns {string[]}
*/
const getObserved = ({ defaultProps }) => defaultProps ? keys(defaultProps) : [];
const getObserved = ({ defaultProps }) =>
defaultProps ? keys(defaultProps) : EMPTY.ARR;

/**
* Creates the `component.props` object.
Expand Down Expand Up @@ -440,4 +442,4 @@ try {
} catch {}

// Automatically subscribe the Component middleware.
Component.subscribeMiddleware();
Component.subscribeMiddleware();
1 change: 1 addition & 0 deletions packages/diffhtml-components/lib/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
export const EMPTY = {
OBJ: {},
ARR: [],
BOOL: true,
};

Expand Down
1 change: 1 addition & 0 deletions packages/diffhtml-devtools/chrome-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Official diffHTML Chrome DevTools Extension",
"permissions": [
"tabs",
"*://*/*",
"http://*/*",
"https://*/*"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/diffhtml-devtools/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
const { use, html, innerHTML, outerHTML } = diff;

// Current broken and not letting text update for some reason...
//use(inlineTransitions());
//use(logger());
use(inlineTransitions());
use(logger());

const animate = (el, ...args) => new Promise(resolve => el.animate(
...args
Expand Down
8 changes: 4 additions & 4 deletions packages/diffhtml-devtools/lib/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const savedRequests = [];

chrome.runtime.onConnect.addListener(port => {
if (port.name === 'devtools-page') {
const devToolsListener = function(message, sender, sendResponse) {
const devToolsListener = message => {
connections.set(message.tabId, port);

savedRequests.forEach(function([id, request]) {
savedRequests.forEach(([id, request]) => {
connections.get(id).postMessage(request);
});

Expand All @@ -23,7 +23,7 @@ chrome.runtime.onConnect.addListener(port => {

port.onMessage.addListener(devToolsListener);

port.onDisconnect.addListener(function(port) {
port.onDisconnect.addListener(port => {
port.onMessage.removeListener(devToolsListener);

connections.forEach((prevPort, tabId) => {
Expand All @@ -37,7 +37,7 @@ chrome.runtime.onConnect.addListener(port => {

// Receive message from content script and relay to the devTools page for the
// current tab
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
chrome.runtime.onMessage.addListener((request, sender) => {
// Messages from content scripts should have sender.tab set
if (sender.tab) {
const { id } = sender.tab;
Expand Down
15 changes: 7 additions & 8 deletions packages/diffhtml-devtools/lib/scripts/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function devTools(Internals) {

function devToolsTask(transaction) {
const {
mount, markup, config, state: { newTree }, state
mount, markup, config, newTree, state
} = transaction;

const isFunction = typeof mount.rawNodeName === 'function';
Expand All @@ -136,9 +136,12 @@ export default function devTools(Internals) {
const startDate = performance.now();

const start = () => {
console.log('Start transaction');
selectors.set(selector, newTree);

extension.activate(getInternals());

return extension.startTransaction(startDate, {
domNode: selector,
mount: selector,
markup,
options: config,
state: assign({}, state, state.nextTransaction && {
Expand All @@ -156,8 +159,6 @@ export default function devTools(Internals) {
start();
}

selectors.set(selector, newTree);

return function() {
// TODO Make patches a separate asynchronous operation, and only
// aggregate when completed.
Expand All @@ -172,7 +173,7 @@ export default function devTools(Internals) {

const { aborted, completed } = transaction;
const stop = () => extension.endTransaction(startDate, endDate, {
domNode: selector,
mount: selector,
markup,
options: config,
state: assign({}, state, state.nextTransaction && {
Expand All @@ -189,8 +190,6 @@ export default function devTools(Internals) {
if (!extension) {
cacheTask.push(() => stop());
} else {

extension.activate(getInternals());
stop();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { html } from 'diffhtml';
import { Component } from 'diffhtml-components';

class DevtoolsTransactionDetail extends Component {
static propTypes = {
transaction: Object,
stats: Object,
closeDetail: Function,
static defaultProps = {
transaction: {},
stats: {},
closeDetail: () => {},
}

state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import SemanticUITable from '../semantic-ui/table';
const { keys } = Object;

class DevtoolsTransactionRow extends Component {
static propTypes = {
index: Number,
transaction: Object,
stateName: String,
startTime: Number,
endTime: Number,
static defaultProps = {
index: -1,
transaction: {},
stateName: '',
startTime: -1,
endTime: -1,
}

render() {
Expand All @@ -25,7 +25,7 @@ class DevtoolsTransactionRow extends Component {
const stats = this.calculateStats();

const {
domNode = '',
mount = '',
aborted = false,
promises = [],
} = transaction;
Expand Down Expand Up @@ -68,7 +68,7 @@ class DevtoolsTransactionRow extends Component {

<td class="ui center aligned">
<div class="node">
&lt;${domNode}&gt;
&lt;${mount}&gt;
</div>
</td>

Expand Down
4 changes: 2 additions & 2 deletions packages/diffhtml-devtools/lib/scripts/components/vtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { keys } = Object;
const { stringify } = JSON;

class DevtoolsVTree extends Component {
static propTypes = {
vTree: Object,
static defaultProps = {
vTree: {},
}

state = {
Expand Down
12 changes: 7 additions & 5 deletions packages/diffhtml-devtools/lib/scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { outerHTML, html, use } from 'diffhtml';
import inlineTransitions from 'diffhtml-middleware-inline-transitions';
import syntheticEvents from 'diffhtml-middleware-synthetic-events';

// Components
import './components/panels';
Expand All @@ -22,7 +23,8 @@ const { stringify, parse } = JSON;
const { assign } = Object;
const background = chrome.runtime.connect({ name: 'devtools-page' });

//use(inlineTransitions());
use(inlineTransitions());
use(syntheticEvents());

use({
// When dark mode is set, automatically add Semantic UI `inverted` class.
Expand Down Expand Up @@ -90,7 +92,8 @@ const fadeIn = el => {
});
};

const render = () => outerHTML(main, html`<main id="main" data-theme=${state.theme}>
const render = () => outerHTML(main, html`
<main id="main" data-theme=${state.theme}>
<devtools-split-view onattached=${fadeIn}>
${Boolean(state.version) && html`
<devtools-navigation
Expand Down Expand Up @@ -146,7 +149,8 @@ const render = () => outerHTML(main, html`<main id="main" data-theme=${state.the
/>
</devtools-panels>
</devtools-split-view>
</main>`).catch(ex => {
</main>
`).catch(ex => {
throw ex;
});

Expand All @@ -159,8 +163,6 @@ background.onMessage.addListener(unparsedMessage => {
case 'activated': {
const clonedData = clone(message.data);

console.log(clonedData);

assign(state, {
...clonedData,
inProgress: clonedData.inProgress || state.inProgress,
Expand Down
1 change: 1 addition & 0 deletions packages/diffhtml-devtools/lib/scripts/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (!window.__diffHTMLDevTools) {
window.__diffHTMLDevTools = () => ({
activate(args={}) {
triggerEvent('activated', args);
this.activated = true;
return this;
},

Expand Down
6 changes: 3 additions & 3 deletions packages/diffhtml-devtools/lib/scripts/panels/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Component } from 'diffhtml-components';
//import ChartistGraph from 'react-chartist';

class DevtoolsHealthPanel extends Component {
static propTypes = {
activeRoute: String,
memory: Array,
static defaultProps = {
activeRoute: '',
memory: [],
}

state = {
Expand Down
8 changes: 4 additions & 4 deletions packages/diffhtml-devtools/lib/scripts/panels/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import diff, { html } from 'diffhtml';
import { Component } from 'diffhtml-components';

class DevtoolsHelpPanel extends Component {
static propTypes = {
theme: String,
activeRoute: String,
version: Number,
static defaultProps = {
theme: '',
activeRoute: '',
version: -1,
}

state = {
Expand Down
6 changes: 3 additions & 3 deletions packages/diffhtml-devtools/lib/scripts/panels/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { html } from 'diffhtml';
import { Component } from 'diffhtml-components';

class DevtoolsMiddlewarePanel extends Component {
static propTypes = {
activeRoute: String,
middleware: Array,
static defaultProps = {
activeRoute: '',
middleware: [],
}

state = {
Expand Down
10 changes: 5 additions & 5 deletions packages/diffhtml-devtools/lib/scripts/panels/mounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { html } from 'diffhtml';
import { Component } from 'diffhtml-components';

class DevtoolsMountsPanel extends Component {
static propTypes = {
mounts: Array,
inspect: Function,
activeRoute: String,
static defaultProps = {
mounts: [],
inspect: () => {},
activeRoute: '',
}

state = {
Expand All @@ -28,7 +28,7 @@ class DevtoolsMountsPanel extends Component {
<style>${styles()}</style>

<div class="ui tall segment">
<h3 onclick=${() => this.setState({ isExpanded: !isExpanded })}>
<h3 onClick=${() => this.setState({ isExpanded: !isExpanded })}>
<i style="position: relative; top: -2px" class="icon chevron ${isExpanded ? 'up' : 'down'}"></i> Mounts
</h3>

Expand Down
16 changes: 8 additions & 8 deletions packages/diffhtml-devtools/lib/scripts/panels/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { html } from 'diffhtml';
import { Component } from 'diffhtml-components';

class DevtoolsTransactionsPanel extends Component {
static propTypes = {
inProgress: Array,
completed: Array,
inspect: Function,
activeRoute: String,
static defaultProps = {
inProgress: [],
completed: [],
inspect: () => {},
activeRoute: '',
}

state = {
Expand All @@ -20,15 +20,15 @@ class DevtoolsTransactionsPanel extends Component {
}

render() {
const { clearEntries, inProgress, completed } = this.props;
const { clearEntries } = this.props;
const {
isExpanded,
autoScroll,
hideEmpty,
activeTransaction,
sorted,
} = this.state;
const { fragment, toggleAutoscroll, toggleHideEmpty } = this;
const { toggleAutoscroll, toggleHideEmpty } = this;

return html`
<link rel="stylesheet" href="/styles/theme.css">
Expand Down Expand Up @@ -286,7 +286,7 @@ class DevtoolsTransactionsPanel extends Component {
}

componentDidUpdate() {
const { isExpanded, expandedIndex, autoScroll } = this.state;
const { expandedIndex, autoScroll } = this.state;

// TODO Have more intelligent locking for scrolling.
if (expandedIndex === -1 && autoScroll) {
Expand Down
9 changes: 9 additions & 0 deletions packages/diffhtml-devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "diffhtml-devtools",
"private": true,
"main": "module/devtools.es5.js",
"scripts": {
"build": "grunt"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/plugin-proposal-class-properties": "^7.12.1",
Expand All @@ -12,6 +15,7 @@
"aliasify": "^2.1.0",
"babel-plugin-add-module-exports": "^1.0.4",
"babel-plugin-transform-custom-element-classes": "^0.1.0",
"babel-plugin-transform-diffhtml": "^1.0.0-beta.18",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babelify": "^10.0.0",
Expand Down Expand Up @@ -55,6 +59,11 @@
}
},
"dependencies": {
"diffhtml": "^1.0.0-beta.18",
"diffhtml-components": "^1.0.0-beta.18",
"diffhtml-middleware-inline-transitions": "^1.0.0-beta.18",
"diffhtml-middleware-synthetic-events": "^1.0.0-beta.18",
"diffhtml-react-compat": "^1.0.0-beta.18",
"hyperlist": "^1.0.0",
"semantic-ui-react": "^2.0.1"
}
Expand Down
Loading