Skip to content

Commit

Permalink
improve logic for getDerivedStateFromProps and webpack4 import
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Apr 6, 2018
1 parent 722d669 commit 00cf1f4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/organism-react-ajax/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "organism-react-ajax",
"version": "0.2.5",
"version": "0.2.6",
"description": "React Ajax with webworker",
"main": "./build/cjs/src/index.js",
"module": "./build/es/src/index.js",
Expand Down
11 changes: 6 additions & 5 deletions packages/organism-react-ajax/src/stores/ajaxStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {Map} from 'immutable';
import {ReduceStore} from 'reshow-flux';
import get from 'get-object-value';
import get, {getDefault} from 'get-object-value';
import smoothScrollTo from 'smooth-scroll-to';

import dispatcher, {ajaxDispatch} from '../ajaxDispatcher';
Expand Down Expand Up @@ -37,8 +37,8 @@ const initWorkerEvent = worker =>

const initFakeWorker = () =>
{
import('../../src/worker').then( ({default: workerObject}) => {
fakeWorker = workerObject;
import('../../src/worker').then( workerObject => {
fakeWorker = getDefault(workerObject);
initWorkerEvent(fakeWorker);
if (!gWorker) {
gWorker = fakeWorker;
Expand Down Expand Up @@ -120,7 +120,8 @@ class AjaxStore extends ReduceStore
if (json.debugs) {
let debugs = json.debugs;
let bFail = false;
import('../lib/dlog').then((dlog)=>{
import('../lib/dlog').then( dlog => {
dlog = getDefault(dlog);
const oLog = new dlog({ level: 'trace'});
debugs.forEach((v)=>{
const dump = get(oLog, [v[0]], ()=>oLog.info);
Expand Down Expand Up @@ -260,7 +261,7 @@ class AjaxStore extends ReduceStore
}
const text = get(action, ['text']);
const response = get(action, ['response']);
const json = get(action, ['json'], this.getJson(text));
const json = get(action, ['json'], () => this.getJson(text));
const callback = this.getCallback(state, action, json, response);
const type = get(json,['type']);
switch (type) {
Expand Down
8 changes: 5 additions & 3 deletions packages/organism-react-ajax/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('es6-promise/auto');
import get from 'get-object-value';
import get, {getDefault} from 'get-object-value';

var ws;
var post;
Expand Down Expand Up @@ -56,7 +56,8 @@ onmessage = (e) =>
const ajaxGet = ({url, action}) =>
{
const params = get(action, ['params'], {});
import('superagent').then((req)=>{
import('superagent').then( req => {
req = getDefault(req);
const headers = {
...get(params, ['globalHeaders'], {}),
...get(params, ['headers'], {}),
Expand All @@ -81,7 +82,8 @@ const ajaxGet = ({url, action}) =>
const ajaxPost = ({url, action}) =>
{
const params = get(action, ['params'], {});
import('superagent').then((req)=>{
import('superagent').then( req => {
req = getDefault(req);
const queryKeys = keys(params.query);
const headers = {
...get(params, ['globalHeaders'], {}),
Expand Down
8 changes: 4 additions & 4 deletions packages/organism-react-ajax/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ browserslist@^2.1.2:
electron-to-chromium "^1.3.30"

caniuse-lite@^1.0.30000792:
version "1.0.30000823"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000823.tgz#b79842a5b5a48eaa416b73f5a5d7a23f52d26014"
version "1.0.30000824"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000824.tgz#de3bc1ba0bff4937302f8cb2a8632a8cc1c07f9a"

caseless@~0.12.0:
version "0.12.0"
Expand Down Expand Up @@ -1183,8 +1183,8 @@ gauge@~2.7.3:
wide-align "^1.1.0"

get-object-value@*:
version "0.0.9"
resolved "https://registry.yarnpkg.com/get-object-value/-/get-object-value-0.0.9.tgz#9450cb8e0f61ed430aaa0d016cde098bc988be39"
version "0.0.11"
resolved "https://registry.yarnpkg.com/get-object-value/-/get-object-value-0.0.11.tgz#c50a528fde734083ceb0dc2b3e1ae74dfb457cb8"

get-safe-reg@*:
version "0.0.0"
Expand Down

0 comments on commit 00cf1f4

Please sign in to comment.