Hello,
Is there a way to use ES6 classes in Oracle JET instead of ES5 prototype classes?
What would I need to do to extend the existing requireJS based workflow to use ES6 classes?
I tried using https://github.com/icecreamliker/requirejs-babel-plugin
In my code below, I am able to import a class if it doesn't import another class.
However, in my example below... my view model is importing an es6 class called PostsFilter, which also imports another es6 module called API.
in the api module, I am getting the following error. Uncaught SyntaxError: Unexpected token export
Do you have any examples of ES6 classes being uses with Oracle JET?
define([
'ojs/ojcore',
'knockout',
'jquery',
'es6!viewModels/posts/postsFilter',
'ojs/ojknockout'
], function (oj, ko, $, PostsFilter) {
function DashboardViewModel() {
self = this;
self.filters = new PostsFilter();
// ...
}
return new DashboardViewModel();
});
import ko from 'knockout';
import api from '../../api';
class PostsFilter {
constructor() {
console.log(api);
this.searchValue = ko.observable('');
this.category = ko.observable(null);
this.searchValue.subscribe(() => {
if (this.onSearch) {
this.onSearch(this.searchValue(), this.category());
}
});
this.categories = ko.observableArray([]);
this.onSearch = null;
api.getCategories().then(res => this.categories(res.data));
}
onSearchChange(value) {
this.searchValue(value);
}
registerSearchHandler(func) {
this.onSearch = (search, category) => func(search, category);
}
}
export default PostsFilter;
const $ = require('jquery');
function getPosts(category, offset) {
return $.getJSON('/data/posts.json');
}
function getCategories() {
return $.getJSON('/data/categories.json');
}
export default {
getPosts,
getCategories,
};