POC for better module import syntax

This commit is contained in:
James
2018-08-13 12:21:55 -04:00
parent ae5a469cd2
commit 256f9fe5b4
6 changed files with 36 additions and 48 deletions

View File

@@ -87,7 +87,7 @@ module.exports = {
],
resolve: {
alias: {
payload: path.resolve(__dirname, '../src'),
payload: path.resolve(__dirname, '../'),
local: path.resolve(__dirname, '../demo')
}
}

View File

@@ -1,16 +1,21 @@
import React from 'react';
import { render } from 'react-dom';
import App from 'payload/client/components/App';
import { Test, Test2 } from 'payload';
import Routes from './Routes';
import store from './store';
// import App from 'payload/client/components/App';
// import Routes from './Routes';
// import store from './store';
console.log(Test);
const Index = () => {
return (
<App store={store}>
<Routes />
</App>
<React.Fragment>
<Test />
<Test2 />
</React.Fragment>
);
};

View File

@@ -1,41 +1 @@
const path = require('path');
const Collection = require('./Collection');
class Payload {
constructor(options) {
this.express = options.express;
this.mongoose = options.mongoose;
this.baseURL = options.baseURL;
this.views = path.join(__dirname, 'views');
this.collections = {};
this.express.get('/payload/admin', (req, res) => {
res.render('admin',
{
title: 'Payload Admin'
});
});
}
newCollection(key) {
if (key in this.collections) {
// TODO: Have discussion about how errors should be handled
return new Error(`${key} already exists in collections`);
}
return new Collection(this, key);
}
getCollection(key) {
if (!(key in this.collections)) {
// TODO: Have discussion about how errors should be handled
return new Error(`${key} does not exist or has not been registered yet`);
}
return this.collections[key];
}
}
module.exports = Payload;
export * from './src/client/Components';

View File

@@ -0,0 +1,9 @@
import React from 'react';
const Test = () => {
return (
<h1>Test</h1>
);
};
export default Test;

View File

@@ -0,0 +1,7 @@
import React from 'react';
export default () => {
return (
<h1>Test2</h1>
);
};

View File

@@ -0,0 +1,7 @@
import Test from './Test';
import Test2 from './Test2';
export {
Test,
Test2
};