Skip to content

Commit

Permalink
Merge pull request #1162 from realityforge/WhitespaceCleanup
Browse files Browse the repository at this point in the history
Replace tabs at the start of comment lines, aligning comments
  • Loading branch information
capaj authored Sep 17, 2017
2 parents 953710b + 3b04a6a commit 016b75f
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 126 deletions.
26 changes: 13 additions & 13 deletions src/api/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { isComputingDerivation } from "../core/derivation"
import { getMessage } from "../utils/messages"

/**
* expr can be used to create temporarily views inside views.
* This can be improved to improve performance if a value changes often, but usually doesn't affect the outcome of an expression.
*
* In the following example the expression prevents that a component is rerender _each time_ the selection changes;
* instead it will only rerenders when the current todo is (de)selected.
*
* reactiveComponent((props) => {
* const todo = props.todo;
* const isSelected = mobx.expr(() => props.viewState.selection === todo);
* return <div className={isSelected ? "todo todo-selected" : "todo"}>{todo.title}</div>
* });
*
*/
* expr can be used to create temporarily views inside views.
* This can be improved to improve performance if a value changes often, but usually doesn't affect the outcome of an expression.
*
* In the following example the expression prevents that a component is rerender _each time_ the selection changes;
* instead it will only rerenders when the current todo is (de)selected.
*
* reactiveComponent((props) => {
* const todo = props.todo;
* const isSelected = mobx.expr(() => props.viewState.selection === todo);
* return <div className={isSelected ? "todo todo-selected" : "todo"}>{todo.title}</div>
* });
*
*/
export function expr<T>(expr: () => T, scope?): T {
if (!isComputingDerivation()) console.warn(getMessage("m013"))
// optimization: would be more efficient if the expr itself wouldn't be evaluated first on the next change, but just a 'changed' signal would be fired
Expand Down
8 changes: 4 additions & 4 deletions src/api/isobservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { isReaction } from "../core/reaction"
import { getMessage } from "../utils/messages"

/**
* Returns true if the provided value is reactive.
* @param value object, function or array
* @param property if property is specified, checks whether value.property is reactive.
*/
* Returns true if the provided value is reactive.
* @param value object, function or array
* @param property if property is specified, checks whether value.property is reactive.
*/
export function isObservable(value, property?: string): boolean {
if (value === null || value === undefined) return false
if (property !== undefined) {
Expand Down
8 changes: 4 additions & 4 deletions src/api/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export class IObservableFactories {
}

/**
* Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
*/
* Decorator that creates an observable that only observes the references, but doesn't try to turn the assigned value into an observable.ts.
*/
ref(target: Object, property: string, descriptor?: PropertyDescriptor): any
ref<T>(initialValue: T): T
ref() {
Expand All @@ -133,8 +133,8 @@ export class IObservableFactories {
}

/**
* Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
*/
* Decorator that creates an observable converts its value (objects, maps or arrays) into a shallow observable structure
*/
shallow(target: Object, property: string, descriptor?: PropertyDescriptor): any
shallow<T>(initialValues: T[]): IObservableArray<T>
shallow<T>(initialValues: IMap<string | number | boolean, T>): ObservableMap<T>
Expand Down
4 changes: 2 additions & 2 deletions src/api/tojs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { isObservableValue } from "../types/observablevalue"
import { isObservable } from "./isobservable"

/**
* Basically, a deep clone, so that no reactive property will exist anymore.
*/
* Basically, a deep clone, so that no reactive property will exist anymore.
*/
export function toJS<T>(source: T, detectCycles?: boolean): T
export function toJS(source: any, detectCycles?: boolean): any
export function toJS(source, detectCycles: boolean, __alreadySeen: [any, any][]) // internal overload
Expand Down
20 changes: 10 additions & 10 deletions src/core/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ export class BaseAtom implements IAtom {
lastAccessedBy = 0
lowestObserverState = IDerivationState.NOT_TRACKING
/**
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
constructor(public name = "Atom@" + getNextId()) {}

public onBecomeUnobserved() {
// noop
}

/**
* Invoke this method to notify mobx that your atom has been used somehow.
*/
* Invoke this method to notify mobx that your atom has been used somehow.
*/
public reportObserved() {
reportObserved(this)
}

/**
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
*/
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
*/
public reportChanged() {
startBatch()
propagateChanged(this)
Expand All @@ -50,9 +50,9 @@ export class Atom extends BaseAtom implements IAtom {
public isBeingTracked = false

/**
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
constructor(
public name = "Atom@" + getNextId(),
public onBecomeObservedHandler: () => void = noop,
Expand Down
28 changes: 14 additions & 14 deletions src/core/computedvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
setter: (value: T) => void

/**
* Create a new computed value based on a function expression.
*
* The `name` property is for debug purposes only.
*
* The `equals` property specifies the comparer function to use to determine if a newly produced
* value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
* compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
* Structural comparison can be convenient if you always produce an new aggregated object and
* don't want to notify observers if it is structurally the same.
* This is useful for working with vectors, mouse coordinates etc.
*/
* Create a new computed value based on a function expression.
*
* The `name` property is for debug purposes only.
*
* The `equals` property specifies the comparer function to use to determine if a newly produced
* value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
* compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
* Structural comparison can be convenient if you always produce an new aggregated object and
* don't want to notify observers if it is structurally the same.
* This is useful for working with vectors, mouse coordinates etc.
*/
constructor(
public derivation: () => T,
public scope: Object | undefined,
Expand All @@ -114,9 +114,9 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
}

/**
* Returns the current value of this computed value.
* Will evaluate its computation first if needed.
*/
* Returns the current value of this computed value.
* Will evaluate its computation first if needed.
*/
public get(): T {
invariant(!this.isComputing, `Cycle detected in computation ${this.name}`, this.derivation)
if (globalState.inBatch === 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/core/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export interface IDerivation extends IDepTreeNode {
newObserving: null | IObservable[]
dependenciesState: IDerivationState
/**
* Id of the current run of a derivation. Each time the derivation is tracked
* this number is increased by one. This number is globally unique
*/
* Id of the current run of a derivation. Each time the derivation is tracked
* this number is increased by one. This number is globally unique
*/
runId: number
/**
* amount of dependencies used by the derivation in this run, which has not been bound yet.
*/
* amount of dependencies used by the derivation in this run, which has not been bound yet.
*/
unboundDepsCount: number
__mapid: string
onBecomeStale()
Expand Down
74 changes: 37 additions & 37 deletions src/core/globalstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,79 @@ const persistentKeys = ["mobxGuid", "resetId", "spyListeners", "strictMode", "ru

export class MobXGlobals {
/**
* MobXGlobals version.
* MobX compatiblity with other versions loaded in memory as long as this version matches.
* It indicates that the global state still stores similar information
*/
* MobXGlobals version.
* MobX compatiblity with other versions loaded in memory as long as this version matches.
* It indicates that the global state still stores similar information
*/
version = 5

/**
* Currently running derivation
*/
* Currently running derivation
*/
trackingDerivation: IDerivation | null = null

/**
* Are we running a computation currently? (not a reaction)
*/
* Are we running a computation currently? (not a reaction)
*/
computationDepth = 0

/**
* Each time a derivation is tracked, it is assigned a unique run-id
*/
* Each time a derivation is tracked, it is assigned a unique run-id
*/
runId = 0

/**
* 'guid' for general purpose. Will be persisted amongst resets.
*/
* 'guid' for general purpose. Will be persisted amongst resets.
*/
mobxGuid = 0

/**
* Are we in a batch block? (and how many of them)
*/
* Are we in a batch block? (and how many of them)
*/
inBatch: number = 0

/**
* Observables that don't have observers anymore, and are about to be
* suspended, unless somebody else accesses it in the same batch
*
* @type {IObservable[]}
*/
* Observables that don't have observers anymore, and are about to be
* suspended, unless somebody else accesses it in the same batch
*
* @type {IObservable[]}
*/
pendingUnobservations: IObservable[] = []

/**
* List of scheduled, not yet executed, reactions.
*/
* List of scheduled, not yet executed, reactions.
*/
pendingReactions: Reaction[] = []

/**
* Are we currently processing reactions?
*/
* Are we currently processing reactions?
*/
isRunningReactions = false

/**
* Is it allowed to change observables at this point?
* In general, MobX doesn't allow that when running computations and React.render.
* To ensure that those functions stay pure.
*/
* Is it allowed to change observables at this point?
* In general, MobX doesn't allow that when running computations and React.render.
* To ensure that those functions stay pure.
*/
allowStateChanges = true
/**
* If strict mode is enabled, state changes are by default not allowed
*/
* If strict mode is enabled, state changes are by default not allowed
*/
strictMode = false

/**
* Used by createTransformer to detect that the global state has been reset.
*/
* Used by createTransformer to detect that the global state has been reset.
*/
resetId = 0

/**
* Spy callbacks
*/
* Spy callbacks
*/
spyListeners: { (change: any): void }[] = []

/**
* Globally attached error handlers that react specifically to errors in reactions
*/
* Globally attached error handlers that react specifically to errors in reactions
*/
globalReactionErrorHandlers: ((error: any, derivation: IDerivation) => void)[] = []
}

Expand Down Expand Up @@ -124,8 +124,8 @@ export function shareGlobalState() {
const ownState = globalState

/**
* Backward compatibility check
*/
* Backward compatibility check
*/
if (global.__mobservableTrackingStack || global.__mobservableViewStack)
throw new Error("[mobx] An incompatible version of mobservable is already loaded.")
if (global.__mobxGlobal && global.__mobxGlobal.version !== ownState.version)
Expand Down
16 changes: 8 additions & 8 deletions src/core/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export interface IDepTreeNode {
export interface IObservable extends IDepTreeNode {
diffValue: number
/**
* Id of the derivation *run* that last accessed this observable.
* If this id equals the *run* id of the current derivation,
* the dependency is already established
*/
* Id of the derivation *run* that last accessed this observable.
* If this id equals the *run* id of the current derivation,
* the dependency is already established
*/
lastAccessedBy: number

lowestObserverState: IDerivationState // Used to avoid redundant propagations
Expand Down Expand Up @@ -141,10 +141,10 @@ export function reportObserved(observable: IObservable) {
const derivation = globalState.trackingDerivation
if (derivation !== null) {
/**
* Simple optimization, give each derivation run an unique id (runId)
* Check if last time this observable was accessed the same runId is used
* if this is the case, the relation is already known
*/
* Simple optimization, give each derivation run an unique id (runId)
* Check if last time this observable was accessed the same runId is used
* if this is the case, the relation is already known
*/
if (derivation.runId !== observable.lastAccessedBy) {
observable.lastAccessedBy = derivation.runId
derivation.newObserving![derivation.unboundDepsCount++] = observable
Expand Down
4 changes: 2 additions & 2 deletions src/core/reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export class Reaction implements IDerivation, IReactionPublic {
}

/**
* internal, use schedule() if you intend to kick off a reaction
*/
* internal, use schedule() if you intend to kick off a reaction
*/
runReaction() {
if (!this.isDisposed) {
startBatch()
Expand Down
16 changes: 8 additions & 8 deletions src/types/observablearray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ export class ObservableArray<T> extends StubArray {
}

/**
* Converts this array back to a (shallow) javascript structure.
* For a deep clone use mobx.toJS
*/
* Converts this array back to a (shallow) javascript structure.
* For a deep clone use mobx.toJS
*/
toJS(): T[] {
return (this as any).slice()
}
Expand Down Expand Up @@ -386,11 +386,11 @@ export class ObservableArray<T> extends StubArray {
}

/*
functions that do alter the internal structure of the array, (based on lib.es6.d.ts)
since these functions alter the inner structure of the array, the have side effects.
Because the have side effects, they should not be used in computed function,
and for that reason the do not call dependencyState.notifyObserved
*/
* functions that do alter the internal structure of the array, (based on lib.es6.d.ts)
* since these functions alter the inner structure of the array, the have side effects.
* Because the have side effects, they should not be used in computed function,
* and for that reason the do not call dependencyState.notifyObserved
*/
splice(index: number, deleteCount?: number, ...newItems: T[]): T[] {
switch (arguments.length) {
case 0:
Expand Down
Loading

0 comments on commit 016b75f

Please sign in to comment.