File tree Expand file tree Collapse file tree 6 files changed +44
-28
lines changed Expand file tree Collapse file tree 6 files changed +44
-28
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import moduleReducer from './sandboxes/modules/reducer';
9
9
import directoryReducer from './sandboxes/directories/reducer' ;
10
10
import userReducer from './sandboxes/users/reducer' ;
11
11
12
- const d = _debug ( 'cw :app:store:reducers:entities' ) ;
12
+ const d = _debug ( 'cs :app:store:reducers:entities' ) ;
13
13
14
14
const entityReducers = {
15
15
sandboxes : sandboxReducer ,
Original file line number Diff line number Diff line change 1
1
// @flow
2
2
import { push } from 'react-router-redux' ;
3
+ import type { Module , Directory } from 'common/types' ;
3
4
4
5
import { createAPIActions , doRequest } from '../../api/actions' ;
5
6
import { normalizeResult } from '../actions' ;
6
7
import notificationActions from '../../notifications/actions' ;
7
8
import entity from './entity' ;
8
9
import fetchBundle from './bundle-loader' ;
9
- import type { Module } from './modules/entity' ;
10
10
import moduleEntity from './modules/entity' ;
11
11
import moduleActions from './modules/actions' ;
12
- import type { Directory } from './directories/entity' ;
13
12
import directoryEntity from './directories/entity' ;
14
13
import directoryActions from './directories/actions' ;
15
14
import { singleSandboxSelector } from './selectors' ;
Original file line number Diff line number Diff line change
1
+ import { singleSandboxSelector } from 'app/store/entities/sandboxes/selectors' ;
2
+
1
3
import callApi from '../../services/api' ;
2
- import delay from '../../services/delay' ;
4
+
5
+ const getDependencyString = npmDependencies => {
6
+ return Object . keys ( npmDependencies )
7
+ . map ( dep => `${ dep } @${ npmDependencies [ dep ] } ` )
8
+ . join ( '+' ) ;
9
+ } ;
3
10
4
11
export default function fetch ( actions , id : string ) {
5
- return async ( dispatch : Function ) => {
12
+ return async ( dispatch : Function , getState : Function ) => {
6
13
dispatch ( { type : actions . REQUEST , initial : true , id } ) ;
7
- const firstResult = await callApi ( '/bundler/bundle' , null , {
8
- method : 'POST' ,
9
- body : { id } ,
10
- } ) ;
11
- dispatch ( { type : actions . SUCCESS , result : firstResult } ) ;
12
14
13
- if ( firstResult . manifest ) {
14
- return firstResult ;
15
- }
15
+ const sandbox = singleSandboxSelector ( getState ( ) , { id } ) ;
16
+ const dependencyString = getDependencyString ( sandbox . npmDependencies ) ;
17
+
18
+ const baseUrl = `https://cdn.jsdelivr.net/webpack/v1/${ dependencyString } ` ;
16
19
17
- while ( true ) {
18
- await delay ( 1000 ) ;
19
- const result = await callApi ( `/bundler/bundle/${ firstResult . hash } ` ) ;
20
+ const manifest = await callApi ( `${ baseUrl } /manifest.json` ) ;
21
+
22
+ const result = {
23
+ manifest,
24
+ url : `${ baseUrl } /dll.js` ,
25
+ } ;
26
+
27
+ dispatch ( {
28
+ type : actions . SUCCESS ,
29
+ result,
30
+ } ) ;
20
31
21
- if ( result . manifest ) {
22
- return result ;
23
- }
24
- }
32
+ return result ;
25
33
} ;
26
34
}
Original file line number Diff line number Diff line change 2
2
import { camelizeKeys , decamelizeKeys } from 'humps' ;
3
3
import axios from 'axios' ;
4
4
5
- import getJwt from '../user/utils/jwt' ;
6
5
import { optionsToParameterizedUrl } from '../../utils/url-generator' ;
7
6
8
7
const API_ROOT = '/api/v1/' ;
@@ -14,6 +13,12 @@ export type BodyType = {
14
13
jwt : ?string ,
15
14
} ;
16
15
16
+ const getUrl = ( url : string ) => {
17
+ if ( url . startsWith ( 'https://' ) ) return url ;
18
+
19
+ return url . split ( '' ) [ 0 ] === '/' ? url : `${ API_ROOT } ${ url } ` ;
20
+ } ;
21
+
17
22
/**
18
23
* Sends a request to the API and returns a promise with camelized response
19
24
*/
@@ -29,9 +34,7 @@ export default (async function callApi(
29
34
if ( ! endpoint ) throw new Error ( 'No endpoint is given' ) ;
30
35
31
36
// If it is an absolute url.
32
- const url = endpoint . split ( '' ) [ 0 ] === '/'
33
- ? endpoint
34
- : `${ API_ROOT } ${ endpoint } ` ;
37
+ const url = getUrl ( endpoint ) ;
35
38
36
39
const options = { url, method } ;
37
40
Original file line number Diff line number Diff line change @@ -59,9 +59,14 @@ export default function evaluateJS(
59
59
// eslint-disable-line no-unused-vars
60
60
if ( / ^ \w / . test ( path ) ) {
61
61
// So it must be a dependency
62
- const dependencyManifest = manifest [ path ] || manifest [ `${ path } .js` ] ;
63
- if ( dependencyManifest ) {
64
- return window . dependencies ( dependencyManifest . id ) ;
62
+ const dependencyModuleIdString = manifest . externals [ path ] ||
63
+ manifest . externals [ `${ path } .js` ] ;
64
+
65
+ const dependencyModuleId = dependencyModuleIdString . match (
66
+ / d l l _ b u n d l e \( ( .* ) \) /
67
+ ) [ 1 ] ;
68
+ if ( dependencyModuleId ) {
69
+ return window . dll_bundle ( dependencyModuleId ) ;
65
70
} else {
66
71
throw new DependencyNotFoundError ( path ) ;
67
72
}
Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ let url = null;
20
20
21
21
async function addDependencyBundle ( ) {
22
22
if ( url !== '' ) {
23
+ window . dll_bundle = null ;
23
24
const script = document . createElement ( 'script' ) ;
24
25
script . setAttribute ( 'src' , url ) ;
25
26
script . setAttribute ( 'async' , false ) ;
26
27
document . head . appendChild ( script ) ;
27
28
28
- while ( window . dependencies == null ) {
29
+ while ( window . dll_bundle == null ) {
29
30
await delay ( 100 ) ;
30
31
}
31
32
}
You can’t perform that action at this time.
0 commit comments