Skip to content

Commit

Permalink
Fixed exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 24, 2018
1 parent 49514b1 commit 4bcdb97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 126 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 4.0.0


## Breaking changes

* Killed the already deprecated modifiers `asFlat` etc. If you war still using this, see the MobX 2 -> 3 migration notes.
Expand All @@ -9,6 +10,8 @@

## Non breaking changes

* Dropped the broken `default` export that made it impossible to tree-shake mobx. Make sure you always use `import { x } from "mobx"` and not `import x from "mobx"`

# 3.4.1

* Republished 3.4.0, because the package update doesn't seem to distibute consistently through yarn / npm
Expand Down
134 changes: 8 additions & 126 deletions src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,134 +135,16 @@ export const extras = {
setReactionScheduler
}

// Deprecated default export (will be removed in 4.0)

import { IObservable } from "./core/observable"
import { Reaction, IReactionPublic, IReactionDisposer } from "./core/reaction"
import { untracked, IDerivationState } from "./core/derivation"
import { IAtom, Atom, BaseAtom } from "./core/atom"
import { useStrict, isStrictModeEnabled, IAction } from "./core/action"
import { spy } from "./core/spy"
import { IComputedValue } from "./core/computedvalue"
import { IEqualsComparer, comparer } from "./types/comparer"
import { IModifierDescriptor, IEnhancer, isModifierDescriptor } from "./types/modifiers"
import { IInterceptable, IInterceptor } from "./types/intercept-utils"
import { IListenable } from "./types/listen-utils"
import {
IObjectWillChange,
IObjectChange,
IObservableObject,
isObservableObject
} from "./types/observableobject"
import {
IValueDidChange,
IValueWillChange,
isObservableValue as isBoxedObservable
} from "./types/observablevalue"
import {
IArrayWillChange,
IArrayWillSplice,
IArrayChange,
IArraySplice,
isObservableArray
} from "./types/observablearray"
import {
IKeyValueMap,
IMapEntries,
IMapEntry,
IMapWillChange,
IMapChange,
IMapChangeUpdate,
IMapChangeAdd,
IMapChangeBase,
IMapChangeDelete,
isObservableMap,
map,
IObservableMapInitialValues,
IMap
} from "./types/observablemap"
import { transaction } from "./api/transaction"
import { observable, IObservableFactory, IObservableFactories } from "./api/observable"
import { computed, IComputed, IComputedValueOptions } from "./api/computed"
import { isObservable } from "./api/isobservable"
import { isComputed } from "./api/iscomputed"
import { extendObservable, extendShallowObservable } from "./api/extendobservable"
import { observe } from "./api/observe"
import { intercept } from "./api/intercept"
import { autorun, autorunAsync, when, reaction, IReactionOptions } from "./api/autorun"
import { action, isAction, runInAction, IActionFactory } from "./api/action"
import { expr } from "./api/expr"
import { toJS } from "./api/tojs"
import { ITransformer, createTransformer } from "./api/createtransformer"
import { whyRun } from "./api/whyrun"
import { isArrayLike } from "./utils/utils"
import { Iterator } from "./utils/iterable"

const everything = {
Reaction,
untracked,
Atom,
BaseAtom,
useStrict,
isStrictModeEnabled,
spy,
comparer,
isModifierDescriptor,
isObservableObject,
isBoxedObservable,
isObservableArray,
ObservableMap,
isObservableMap,
map,
transaction,
observable,
computed,
isObservable,
isComputed,
extendObservable,
extendShallowObservable,
observe,
intercept,
autorun,
autorunAsync,
when,
reaction,
action,
isAction,
runInAction,
expr,
toJS,
createTransformer,
whyRun,
isArrayLike,
extras
}

let warnedAboutDefaultExport = false

for (let p in everything) {
let val = everything[p]
Object.defineProperty(everything, p, {
get: () => {
if (!warnedAboutDefaultExport) {
warnedAboutDefaultExport = true
console.warn(
"Using default export (`import mobx from 'mobx'`) is deprecated " +
"and won’t work in [email protected]\n" +
"Use `import * as mobx from 'mobx'` instead"
)
}
return val
}
})
}

// TODO: remove in 4.0, temporarily incompatibility fix for [email protected] which accidentally uses default exports
export default everything

// Devtools support
import { spy } from "./core/spy"

declare var __MOBX_DEVTOOLS_GLOBAL_HOOK__: { injectMobx: ((any) => void) }
if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({ spy, extras })
// See: https://github.com/andykog/mobx-devtools/
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({
spy,
extras: {
getDebugName
}
})
}

4 comments on commit 4bcdb97

@mesqueeb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently you have

export {
// individual exports
} from "./internal"

But what about:

export * from "./internal"

Would this make it impossible to tree-shake?

@mweststrate
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but not everything that is exposed from internal is supposed to be part of the public interface.

@mesqueeb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mweststrate
I understand you don't wanna expose everything.
But are you saying that theoretically export * from "./internal" would make it impossible to tree-shake?

@mweststrate
Copy link
Member Author

@mweststrate mweststrate commented on 4bcdb97 Sep 28, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.