Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: modernize the code slightly by using import/export #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
test-browser/build.js
node_modules
bundle.js
bundle.js.map
bundle.*
stats.html
2 changes: 1 addition & 1 deletion default-router-options.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { reverse: false }
export default { reverse: false }
36 changes: 18 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const StateState = require('./lib/state-state')
const StateComparison = require('./lib/state-comparison')
const CurrentState = require('./lib/current-state')
const stateChangeLogic = require('./lib/state-change-logic')
const parse = require('./lib/state-string-parser')
const StateTransitionManager = require('./lib/state-transition-manager')
const defaultRouterOptions = require('./default-router-options.js')

const series = require('./lib/promise-map-series')
const extend = require('./lib/extend.js')

const denodeify = require('then-denodeify')
const EventEmitter = require('eventemitter3')
const newHashBrownRouter = require('hash-brown-router')
const combine = require('combine-arrays')
const buildPath = require('page-path-builder')
const nextTick = require('iso-next-tick')
import StateState from './lib/state-state.js'
import StateComparison from './lib/state-comparison.js'
import CurrentState from './lib/current-state.js'
import stateChangeLogic from './lib/state-change-logic.js'
import parse from './lib/state-string-parser.js'
import StateTransitionManager from './lib/state-transition-manager.js'
import defaultRouterOptions from './default-router-options.js'

import series from './lib/promise-map-series.js'
import extend from './lib/extend.js'

import denodeify from 'then-denodeify'
import EventEmitter from 'eventemitter3'
import newHashBrownRouter from 'hash-brown-router'
import combine from 'combine-arrays'
import buildPath from 'page-path-builder'
import nextTick from 'iso-next-tick'

const getProperty = name => obj => obj[name]
const reverse = ary => ary.slice().reverse()
Expand All @@ -24,7 +24,7 @@ const promiseMe = (fn, ...args) => new Promise(resolve => resolve(fn(...args)))

const expectedPropertiesOfAddState = [ 'name', 'route', 'defaultChild', 'data', 'template', 'resolve', 'activate', 'querystringParameters', 'defaultQuerystringParameters', 'defaultParameters' ]

module.exports = function StateProvider(makeRenderer, rootElement, stateRouterOptions = {}) {
export default (makeRenderer, rootElement, stateRouterOptions = {}) => {
const prototypalStateHolder = StateState()
const lastCompletelyLoadedState = CurrentState()
const lastStateStartedActivating = CurrentState()
Expand Down
2 changes: 1 addition & 1 deletion lib/current-state.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function CurrentState() {
export default () => {
let current = {
name: '',
parameters: {},
Expand Down
2 changes: 1 addition & 1 deletion lib/extend.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = (...args) => Object.assign({}, ...args)
export default (...args) => Object.assign({}, ...args)
2 changes: 1 addition & 1 deletion lib/promise-map-series.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Pulled from https://github.com/joliss/promise-map-series and prettied up a bit

module.exports = function sequence(array, iterator) {
export default (array, iterator) => {
let currentPromise = Promise.resolve()
return Promise.all(
array.map((value, i) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/state-change-logic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function stateChangeLogic(stateComparisonResults) {
export default stateComparisonResults => {
let hitChangingState = false
let hitDestroyedState = false

Expand Down
10 changes: 5 additions & 5 deletions lib/state-comparison.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const stateStringParser = require('./state-string-parser')
const extend = require('./extend.js')
import stateStringParser from './state-string-parser.js'
import extend from './extend.js'

const combine = require('combine-arrays')
const pathToRegexp = require('path-to-regexp-with-reversible-keys')
import combine from 'combine-arrays'
import pathToRegexp from 'path-to-regexp-with-reversible-keys'

module.exports = function StateComparison(stateState) {
export default stateState => {
const getPathParameters = pathParameters()

const parametersChanged = args => parametersThatMatterWereChanged(extend(args, { stateState, getPathParameters }))
Expand Down
8 changes: 3 additions & 5 deletions lib/state-state.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const stateStringParser = require('./state-string-parser')
import stateStringParser from './state-string-parser.js'

module.exports = function StateState() {
export default function () {
const states = {}

function getHierarchy(name) {
const names = stateStringParser(name)

return names.map(name => {
return stateStringParser(name).map(name => {
if (!states[name]) {
throw new Error(`State ${name} not found`)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/state-string-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = stateString => {
export default stateString => {
return stateString.split('.').reduce((stateNames, latestNameChunk) => {
stateNames.push(
stateNames.length
Expand Down
2 changes: 1 addition & 1 deletion lib/state-transition-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = emitter => {
export default emitter => {
let currentTransitionAttempt = null
let nextTransition = null

Expand Down
5 changes: 3 additions & 2 deletions test/helpers/test-state-factory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const hashRouterFactory = require('hash-brown-router')
const hashLocationMockFactory = require('hash-brown-router/hash-location-mock')
const stateRouterFactory = require('../../')
const defaultRouterOptions = require('../../default-router-options.js')
const mockRenderFn = require('./renderer-mock')

import stateRouterFactory from '../../index.js'
import defaultRouterOptions from '../../default-router-options.js'

module.exports = function getTestState(t, renderFn, options) {
const location = hashLocationMockFactory()
const hashRouter = hashRouterFactory(defaultRouterOptions, location)
Expand Down
2 changes: 1 addition & 1 deletion test/interpreting-state-changes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('tape-catch')

const interpretStateChange = require('../lib/state-change-logic')
import interpretStateChange from '../lib/state-change-logic.js'

test('State change logic', function(t) {
function check(description, input, expected) {
Expand Down
2 changes: 1 addition & 1 deletion test/promise-map-series.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copied from https://github.com/joliss/promise-map-series/blob/master/test.js

const test = require('tape-catch')
const mapSeries = require('../lib/promise-map-series')
import mapSeries from '../lib/promise-map-series.js'

test('mapSeries', function(t) {
t.test('iterator is called in sequence for each item', function(t) {
Expand Down
4 changes: 2 additions & 2 deletions test/state-comparison.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('tape-catch')
const StateState = require('../lib/state-state.js')
const stateComparison = require('../lib/state-comparison.js')
import StateState from '../lib/state-state.js'
import stateComparison from '../lib/state-comparison.js'

function simpleState(name, querystringParameters, route = '') {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/state-state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('tape-catch')
const StateState = require('../lib/state-state')
import StateState from '../lib/state-state.js'

/*
stateState.add
Expand Down
2 changes: 1 addition & 1 deletion test/state-string-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('tape-catch')
const parse = require('../lib/state-string-parser')
import parse from '../lib/state-string-parser'

function testParsing(t, input, output) {
t.deepEqual(parse(input), output, `${input} produces ${output.length} results`)
Expand Down