-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from scssyworks/feature/ver4
Feature/ver4
- Loading branch information
Showing
19 changed files
with
2,227 additions
and
2,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"no-console": 1 | ||
"no-console": 1, | ||
"no-undef": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"endOfLine": "auto" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
import { fromEvent } from 'rxjs'; | ||
import { POP_STATE, QRY, VIRTUAL_PUSHSTATE } from '../../utils/constants'; | ||
import { POP_STATE, VIRTUAL_PUSHSTATE } from '../../utils/constants'; | ||
import { trigger } from '../../utils/triggerEvent'; | ||
import collate from '../collate'; | ||
import { trim } from '../../utils/utils'; | ||
import { getGlobal } from '../../utils/getGlobal'; | ||
import { getPath } from '../../utils/getPath'; | ||
|
||
export default function bindRouterEvents() { | ||
const { context, location, hashRouting } = this.config; | ||
this.popStateSubscription = fromEvent(getGlobal(), POP_STATE).subscribe( | ||
export default function bindRouterEvents(inst) { | ||
const { context, location, hashRouting: hash } = inst.config; | ||
inst.popStateSubscription = fromEvent(getGlobal(), POP_STATE).subscribe( | ||
(e) => { | ||
const path = trim( | ||
hashRouting | ||
? location.hash.substring(1).split(QRY)[0] | ||
: location.pathname | ||
); | ||
const path = getPath(hash, location); | ||
if (path) { | ||
trigger(context, VIRTUAL_PUSHSTATE, [ | ||
{ path, hash: hashRouting }, | ||
e, | ||
this, | ||
]); | ||
trigger(context, VIRTUAL_PUSHSTATE, [{ path, hash }, e, inst]); | ||
} | ||
} | ||
); | ||
this.listeners = fromEvent(context, VIRTUAL_PUSHSTATE).pipe( | ||
collate.apply(this) | ||
inst.listeners = fromEvent(context, VIRTUAL_PUSHSTATE).pipe( | ||
collate.apply(inst) | ||
); | ||
if (hashRouting && !location.hash) { | ||
this.set('/', true, false); // Replace current hash path without executing anythings | ||
if (hash && !location.hash) { | ||
inst.set('/', true, false); // Replace current hash path without executing anythings | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import './utils/polyfills'; | ||
import Router from './api/router'; | ||
import * as operators from './operators'; | ||
import Router from "./api/router"; | ||
import * as operators from "./operators"; | ||
|
||
export { Router, operators }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
import { isObject } from "deparam.js"; | ||
import { each } from "./utils"; | ||
|
||
/** | ||
* Inner loop function for assign | ||
* @private | ||
* @param {object} ref Argument object | ||
* @param {object} target First object | ||
*/ | ||
function loopFunc(ref, target) { | ||
if (isObject(ref)) { | ||
each(ref, (prop, key) => { | ||
target[key] = prop; | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Polyfill for Object.assign only smaller and with less features | ||
* Function to extend an object with new and updated properties | ||
* @private | ||
* @returns {object} | ||
*/ | ||
export function assign(...args) { | ||
const target = isObject(args[0]) ? args[0] : {}; | ||
each(args, (arg) => { | ||
loopFunc(arg, target); | ||
}); | ||
return target; | ||
return Object.assign(...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { QRY } from './constants'; | ||
import { trim } from './utils'; | ||
|
||
export const getPath = (isHash, location) => { | ||
return trim( | ||
isHash ? location.hash.substring(1).split(QRY)[0] : location.pathname | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { isValidRoute, trim } from '../src/js/utils/utils'; | ||
|
||
describe('Utils', () => { | ||
describe('trim', () => { | ||
it('should trim text', () => { | ||
expect(trim(' test ')).toBe('test'); | ||
}); | ||
it('should return empty string if input value is invalid', () => { | ||
expect(trim(null)).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('isValidRoute', () => { | ||
it('should return true of route is valid', () => { | ||
expect(isValidRoute('/test/path')).toBeTruthy(); | ||
}); | ||
it('should return false of route is INVALID', () => { | ||
expect(isValidRoute('test/path')).toBeFalsy(); | ||
}); | ||
it('should return false of route is UNDEFINED or NULL', () => { | ||
expect(isValidRoute()).toBeFalsy(); | ||
expect(isValidRoute(null)).toBeFalsy(); | ||
}); | ||
}); | ||
}); |