make block script ES5 compatible
There are polyfills for methods like apiFetch, so migrate the syntax to ES5 (no generators, method shorthands, arrow functions, ...) and we are done here without adding transpilers to the project.
This commit is contained in:
parent
df1de841e8
commit
dd074293a7
@ -4,43 +4,39 @@
|
|||||||
* Gutenberg Block to integrate the liveticker widget without shortcode.
|
* Gutenberg Block to integrate the liveticker widget without shortcode.
|
||||||
*/
|
*/
|
||||||
( function() {
|
( function() {
|
||||||
var { __ } = wp.i18n;
|
var __ = wp.i18n.__;
|
||||||
var { registerBlockType } = wp.blocks;
|
var registerBlockType = wp.blocks.registerBlockType;
|
||||||
var { registerStore, withSelect } = wp.data;
|
var registerStore = wp.data.registerStore;
|
||||||
|
var withSelect = wp.data.withSelect;
|
||||||
var el = wp.element.createElement;
|
var el = wp.element.createElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Datastore actions.
|
* Datastore actions.
|
||||||
*/
|
*/
|
||||||
var actions = {
|
var actions = {
|
||||||
setTickers( tickers ) {
|
setTickers: function( tickers ) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_TICKERS',
|
type: 'SET_TICKERS',
|
||||||
tickers,
|
tickers: tickers,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getTickers( path ) {
|
getTickers: function( path ) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_TICKERS',
|
type: 'RECEIVE_TICKERS',
|
||||||
path,
|
path: path,
|
||||||
};
|
|
||||||
},
|
|
||||||
loadTickers( path ) {
|
|
||||||
return {
|
|
||||||
type: 'LOAD_TICKERS',
|
|
||||||
path,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
registerStore( 'scliveticker/ticker', {
|
registerStore( 'scliveticker/ticker', {
|
||||||
reducer( state = { tickers: null }, action ) {
|
reducer: function( state, action ) {
|
||||||
|
if ( undefined === state ) {
|
||||||
|
state = { tickers: null };
|
||||||
|
}
|
||||||
switch ( action.type ) {
|
switch ( action.type ) {
|
||||||
case 'SET_TICKERS':
|
case 'SET_TICKERS':
|
||||||
return {
|
state.tickers = action.tickers;
|
||||||
...state,
|
return state;
|
||||||
tickers: action.tickers,
|
|
||||||
};
|
|
||||||
case 'RECEIVE_TICKERS':
|
case 'RECEIVE_TICKERS':
|
||||||
return action.tickers;
|
return action.tickers;
|
||||||
}
|
}
|
||||||
@ -48,30 +44,24 @@
|
|||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
actions,
|
actions: actions,
|
||||||
|
|
||||||
selectors: {
|
selectors: {
|
||||||
receiveTickers( state ) {
|
receiveTickers: function( state ) {
|
||||||
const { tickers } = state;
|
return state.tickers;
|
||||||
return tickers;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
controls: {
|
|
||||||
LOAD_TICKERS( action ) {
|
|
||||||
return wp.apiFetch( { path: action.path } );
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
resolvers: {
|
resolvers: {
|
||||||
* receiveTickers() {
|
receiveTickers: function() {
|
||||||
const tickers = yield actions.loadTickers( '/wp/v2/scliveticker_ticker' );
|
return wp.apiFetch( { path: '/wp/v2/scliveticker_ticker' } ).then( function( tickers ) {
|
||||||
return actions.setTickers( tickers.map( function( t ) {
|
return actions.setTickers( tickers.map( function( t ) {
|
||||||
return {
|
return {
|
||||||
name: t.name,
|
name: t.name,
|
||||||
slug: t.slug,
|
slug: t.slug,
|
||||||
};
|
};
|
||||||
} ) );
|
} ) );
|
||||||
|
} );
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
@ -97,7 +87,7 @@
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
edit: withSelect( ( select ) => {
|
edit: withSelect( function( select ) {
|
||||||
return {
|
return {
|
||||||
tickers: select( 'scliveticker/ticker' ).receiveTickers(),
|
tickers: select( 'scliveticker/ticker' ).receiveTickers(),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user