1
使用以下命令來運行我的Web應用程序的時候,我發現了以下錯誤:節點--harmony gulpfile.babelReact.js - operationStore.getItems不是一個函數
遺漏的類型錯誤:operationStore.getItems不一個函數
我甚至不知道問題是什麼。這裏是吞噬文件和錯誤發生的地方。
此代碼先前在index.ejs文件中聲明我的app.js外部的所有內容時都有效。但是這阻止了我在服務器端文件中使用es6,這是我需要的。所以我死了,使用 - 和諧標誌將允許我使用es6。但是我無法克服當我使用和諧標誌時發生的這個錯誤。
getItems對我來說顯然是一個函數,發生了什麼?
Main.jsx
var Login = require('./auth/LogApp.jsx');
var operationStore = require('./stores/OperationStore.jsx');
var initial = operationStore.getItems();
Gulpfile.babel.js
var gulp = require('gulp');
var LiveServer = require('gulp-live-server');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
gulp.task('live-server', function(){
var server = new LiveServer('server/main.js');
server.start();
})
gulp.task('bundle',['copy'], function(){
return browserify({
entries:'app/main.jsx',
jquery : 'jquery-browserify',
debug:true,
})
.transform(babelify,
{
"presets": ["es2015", "react", "stage-1"],
"plugins": ["transform-decorators-legacy", "transform-function-bind"],
extensions: [".jsx", ".js",]
})
.bundle()
.pipe(source('app.js'))
.pipe(gulp.dest('./.tmp'));
})
gulp.task('copy', function() {
gulp.src(['app/*.css', 'app/Icons/**/*','app/stores/**/*', 'app/helper/**/*', 'app/dispatcher.js','bundle.js', 'app/helpers/RestHelper.js',
'app/actions/OperationActionCreator.jsx', 'app/actions/SurgeonActionCreator.jsx',
'app/actions/PatientActionCreator.jsx','app/actions/ORActionCreator.jsx',
'node_modules/guid/guid.js','node_modules/jquery/**/*', 'bower_components*/**/*'])
.pipe(gulp.dest('./.tmp'));
})
gulp.task('serve', ['bundle', 'live-server'], function(){
browserSync.init(null,{
proxy:"http://localhost:7777",
port: 9001
})
})
gulp.run('serve')
OperationStore.jsx
var operationStore = function() {
var operations = [];
var listeners = [];
var updateOperations = function(helper){
helper.get("api/operations")
.then(function(data){
operations = data;
triggerListeners(listeners);
});
}
updateOperations(helper);
function getItems(){
return operations;
};
var addOperationItem = function(operation) {
operations.push(operation);
triggerListeners(listeners);
helper.post("api/operations", operation);
}
var deleteOperationItem = function (operation) {
var index;
operations.filter(function (_operation, _index) {
if (_operation.name == operation.name) {
index = _index;
}
});
operations.splice(operation, 1);
triggerListeners(listeners);
//added this
helper.del('api/operations/'+ operation._id);
}
var onChange = function(listener){
listeners.push(listener);
return listeners;
}
var triggerListeners = function(listeners) {
listeners.forEach(function(listener) {
listener(operations);
})
}
var registerEvent = function (event) {
var split = event.type.split(':');
if (split[0] === 'operation-item') {
switch (split[1]) {
case "add":
addOperationItem(event.payload);
break;
case "delete":
deleteOperationItem(event.payload);
break;
}
}
}
var dispatchRegister = function(dispatcher) {
dispatcher.register(registerEvent);
}
dispatchRegister(dispatcher);
return {
getItems: getItems,
onChange: onChange,
addOperationItem: addOperationItem,
deleteOperationItem: deleteOperationItem,
triggerListeners: triggerListeners,
dispatchRegister: dispatchRegister,
registerEvent: registerEvent,
updateOperations: updateOperations
}
}();