mirror of
https://github.com/xodio/xod.git
synced 2026-03-22 00:26:54 +01:00
refactor(xod-client): don’t include a copy of stdlib in initialState
This commit is contained in:
@@ -6,7 +6,6 @@ import DevTools from '../../utils/devtools';
|
||||
import generateReducers from '../reducer';
|
||||
import initialState from '../state';
|
||||
import EditorMiddleware from '../middlewares';
|
||||
import { addNode, addLink } from '../actions';
|
||||
|
||||
export default class Root extends React.Component {
|
||||
|
||||
@@ -20,34 +19,6 @@ export default class Root extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.populateDemo();
|
||||
}
|
||||
|
||||
populateDemo() {
|
||||
const nodes = [];
|
||||
|
||||
const dispatchAddNode = (nodeTypeKey, x, y) => {
|
||||
const action = addNode(nodeTypeKey, { x, y }, '@/1');
|
||||
const newNodeId = this.store.dispatch(action);
|
||||
nodes.push(newNodeId);
|
||||
};
|
||||
const dispatchAddLink = (o1, o2) => {
|
||||
const action = addLink(o1, o2);
|
||||
this.store.dispatch(action);
|
||||
};
|
||||
|
||||
dispatchAddNode('xod/core/button', 138, 120);
|
||||
dispatchAddNode('xod/core/pot', 394, 120);
|
||||
dispatchAddNode('xod/core/led', 138, 432);
|
||||
dispatchAddNode('xod/core/servo', 394, 432);
|
||||
|
||||
dispatchAddLink(
|
||||
{ nodeId: nodes[0], pinKey: 'state' },
|
||||
{ nodeId: nodes[2], pinKey: 'brightness' }
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Provider store={this.store}>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,24 @@
|
||||
// TODO: Replace this hard-coded state with nodeType providers and empty defaults
|
||||
|
||||
import initialState from './initialProjectStateWithStdlib';
|
||||
|
||||
export default initialState;
|
||||
export default {
|
||||
authors: [
|
||||
'Amperka team',
|
||||
],
|
||||
description: '',
|
||||
license: '',
|
||||
name: 'Awesome project',
|
||||
patches: {
|
||||
'@/1': {
|
||||
impls: {},
|
||||
links: {},
|
||||
nodes: {},
|
||||
path: '@/1',
|
||||
},
|
||||
'@/2': {
|
||||
impls: {},
|
||||
links: {},
|
||||
nodes: {},
|
||||
path: '@/2',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@ describe('project reducer', () => {
|
||||
);
|
||||
|
||||
it('should add a node', () => {
|
||||
const nodeId = store.dispatch(addNode('xod/core/button', { x: 0, y: 0 }, testPatchPath));
|
||||
const nodeId = store.dispatch(addNode('xod/patch-nodes/input-number', { x: 0, y: 0 }, testPatchPath));
|
||||
|
||||
const maybeNode = R.compose(
|
||||
getNodeById(nodeId),
|
||||
@@ -166,7 +166,7 @@ describe('project reducer', () => {
|
||||
assert.isTrue(Maybe.isJust(maybeNode));
|
||||
});
|
||||
it('should move a node', () => {
|
||||
const nodeId = store.dispatch(addNode('xod/core/button', { x: 0, y: 0 }, testPatchPath));
|
||||
const nodeId = store.dispatch(addNode('xod/patch-nodes/input-number', { x: 0, y: 0 }, testPatchPath));
|
||||
const desiredPosition = { x: 111, y: 222 };
|
||||
store.dispatch(moveNode(nodeId, desiredPosition));
|
||||
|
||||
@@ -184,7 +184,7 @@ describe('project reducer', () => {
|
||||
);
|
||||
});
|
||||
it('should update node label', () => {
|
||||
const nodeId = store.dispatch(addNode('xod/core/button', { x: 0, y: 0 }, testPatchPath));
|
||||
const nodeId = store.dispatch(addNode('xod/patch-nodes/input-number', { x: 0, y: 0 }, testPatchPath));
|
||||
const desiredLabel = 'desired label';
|
||||
store.dispatch(updateNodeProperty(nodeId, 'property', 'label', desiredLabel));
|
||||
|
||||
@@ -202,9 +202,9 @@ describe('project reducer', () => {
|
||||
);
|
||||
});
|
||||
it('should update node\'s pin value ', () => {
|
||||
const nodeId = store.dispatch(addNode('xod/core/pot', { x: 0, y: 0 }, testPatchPath));
|
||||
const pinKey = 'sample';
|
||||
const desiredPinValue = true;
|
||||
const nodeId = store.dispatch(addNode('xod/patch-nodes/output-number', { x: 0, y: 0 }, testPatchPath));
|
||||
const pinKey = '__in__';
|
||||
const desiredPinValue = 42;
|
||||
store.dispatch(updateNodeProperty(nodeId, 'pin', pinKey, desiredPinValue));
|
||||
|
||||
const maybeNode = R.compose(
|
||||
@@ -223,7 +223,7 @@ describe('project reducer', () => {
|
||||
);
|
||||
});
|
||||
it('should delete a node', () => {
|
||||
const nodeId = store.dispatch(addNode('xod/core/button', { x: 0, y: 0 }, testPatchPath));
|
||||
const nodeId = store.dispatch(addNode('xod/patch-nodes/input-number', { x: 0, y: 0 }, testPatchPath));
|
||||
store.dispatch(deleteNode(nodeId));
|
||||
|
||||
const maybeNode = R.compose(
|
||||
@@ -239,23 +239,23 @@ describe('project reducer', () => {
|
||||
describe('Link management', () => {
|
||||
let store = null;
|
||||
let testPatchPath = '';
|
||||
let potNodeId = '';
|
||||
let ledNodeId = '';
|
||||
let inNodeId = '';
|
||||
let outNodeId = '';
|
||||
|
||||
beforeEach(
|
||||
() => {
|
||||
store = createStore(generateReducers(), initialState, applyMiddleware(thunk));
|
||||
const addPatchAction = store.dispatch(addPatch('test-patch'));
|
||||
testPatchPath = addPatchAction.payload.patchPath;
|
||||
potNodeId = store.dispatch(addNode('xod/core/pot', { x: 100, y: 100 }, testPatchPath));
|
||||
ledNodeId = store.dispatch(addNode('xod/core/led', { x: 500, y: 500 }, testPatchPath));
|
||||
inNodeId = store.dispatch(addNode('xod/patch-nodes/input-number', { x: 100, y: 100 }, testPatchPath));
|
||||
outNodeId = store.dispatch(addNode('xod/patch-nodes/output-number', { x: 500, y: 500 }, testPatchPath));
|
||||
}
|
||||
);
|
||||
|
||||
it('should add a link', () => {
|
||||
store.dispatch(addLink(
|
||||
{ nodeId: potNodeId, pinKey: 'value' },
|
||||
{ nodeId: ledNodeId, pinKey: 'brightness' }
|
||||
{ nodeId: inNodeId, pinKey: '__out__' },
|
||||
{ nodeId: outNodeId, pinKey: '__in__' }
|
||||
));
|
||||
|
||||
const links = R.compose(
|
||||
@@ -269,8 +269,8 @@ describe('project reducer', () => {
|
||||
|
||||
it('should delete a link', () => {
|
||||
store.dispatch(addLink(
|
||||
{ nodeId: potNodeId, pinKey: 'value' },
|
||||
{ nodeId: ledNodeId, pinKey: 'brightness' }
|
||||
{ nodeId: inNodeId, pinKey: '__out__' },
|
||||
{ nodeId: outNodeId, pinKey: '__in__' }
|
||||
));
|
||||
|
||||
const linkId = R.compose(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import thunk from 'redux-thunk';
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import { default as chai, expect } from 'chai';
|
||||
@@ -9,19 +8,67 @@ import { transpileForEspruino } from 'xod-js';
|
||||
|
||||
import initialState from '../src/core/state';
|
||||
import generateReducers from '../src/core/reducer';
|
||||
import { addNode } from '../src/project/actions';
|
||||
import { addNode, openProject } from '../src/project/actions';
|
||||
import { getProject } from '../src/project/selectors';
|
||||
|
||||
chai.use(dirtyChai);
|
||||
|
||||
const initialProject = {
|
||||
authors: [
|
||||
'Amperka team',
|
||||
],
|
||||
description: '',
|
||||
license: '',
|
||||
name: 'Awesome project',
|
||||
patches: {
|
||||
'@/main': {
|
||||
impls: {},
|
||||
links: {},
|
||||
nodes: {},
|
||||
path: '@/main',
|
||||
},
|
||||
'xod/core/button': {
|
||||
impls: {
|
||||
espruino: "\nmodule.exports.setup = function(e) {\n var pin = new Pin(e.props.pin);\n\n setWatch(function(evt) {\n e.fire({ state: !evt.state });\n }, pin, {\n edge: 'both',\n repeat: true,\n debounce: 30\n });\n};\n",
|
||||
},
|
||||
links: {},
|
||||
nodes: {
|
||||
noNativeImpl: {
|
||||
description: '',
|
||||
id: 'noNativeImpl',
|
||||
label: '',
|
||||
position: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
type: 'xod/patch-nodes/not-implemented-in-xod',
|
||||
},
|
||||
state: {
|
||||
id: 'state',
|
||||
type: 'xod/patch-nodes/output-boolean',
|
||||
position: {
|
||||
x: 0,
|
||||
y: 300,
|
||||
},
|
||||
label: '',
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
path: 'xod/core/button',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
describe('xod-client regression -> xod-js', () => {
|
||||
it('should transpile example initial state to kinda valid code', () => {
|
||||
const store = createStore(generateReducers(), initialState, applyMiddleware(thunk));
|
||||
store.dispatch(addNode('xod/core/button', { x: 100, y: 100 }, '@/1'));
|
||||
store.dispatch(openProject(initialProject));
|
||||
store.dispatch(addNode('xod/core/button', { x: 100, y: 100 }, '@/main'));
|
||||
|
||||
const project = getProject(store.getState());
|
||||
|
||||
const code = explode(transpileForEspruino(project, '@/1'));
|
||||
const code = explode(transpileForEspruino(project, '@/main'));
|
||||
|
||||
// We test the code generated by fare evaluation. Yes, this
|
||||
// will inject variables to the scope, so we limit it with an
|
||||
|
||||
Reference in New Issue
Block a user