Skip to content

Instantly share code, notes, and snippets.

View mweststrate's full-sized avatar
💭
I may be slow to respond.

Michel Weststrate mweststrate

💭
I may be slow to respond.
View GitHub Profile
@mweststrate
mweststrate / fixed.js
Last active January 17, 2023 16:45
circular-deps-4
// -- app.js --
import { AbstractNode } from './internal'
/* as is */
// -- internal.js --
export * from './AbstractNode'
export * from './Node'
export * from './Leaf'
@mweststrate
mweststrate / broken2.js
Created July 17, 2018 13:00
ciruclar-deps-3
export class AbstractNode {
/* as is */
}
import { Node } from './Node'
import { Leaf } from './Leaf'
@mweststrate
mweststrate / broken.js
Created July 17, 2018 12:41
Broken dependencies
// -- AbstractNode.js --
import { Leaf } from './Leaf'
import { Node } from './Node'
export class AbstractNode {
/* as is */
}
// -- Node.js --
import { AbstractNode } from './Node'
@mweststrate
mweststrate / AbstractNode.js
Created July 17, 2018 12:14
circular-deps-1
export class AbstractNode {
constructor(parent) {
this.parent = parent
}
getDepth() {
if (this.parent) return this.parent.getDepth() + 1
return 0
}
Object.defineProperty(observable([]).constructor.prototype, Symbol.isConcatSpreadable, {
enumerable: false, configurable: true, value: true
})
@mweststrate
mweststrate / doc structure proposal.md
Created March 11, 2018 10:36
doc structure proposal.md
  • philosophy
  • overview
    • observables
    • reactions: autorun
    • derived values: computed
    • actions

Making things observable

  • observable.box
  • observable.object
@mweststrate
mweststrate / city.js
Last active August 7, 2019 11:05
City.js
import { decorate, observable, flow, onBecomeObserved, onBecomeUnobserved } from 'mobx'
import { log } from './log'
const APPID = '<secret>'
export class City {
location
temperature
interval
@mweststrate
mweststrate / when.js
Created March 6, 2018 14:59
Async when
import { when } from "mobx"
async() => {
await when(() => user.loggedOut)
alert("You have been successfully logged out!")
}
@mweststrate
mweststrate / decorators.js
Last active March 12, 2018 19:46
Decorators in MobX
import { decorate, observable, flow } from "mobx"
/**
with decorator syntax enabled
*/
class City {
@observable location
@observable temperature
@action.bound
@mweststrate
mweststrate / cityview.js
Created March 6, 2018 14:43
CityView component
const CityView = observer(({ city }) => (
<li>
City: {city.location} - Temperature in ℃: {city.temperature || 'Loading'}
</li>
))