Created
February 13, 2019 15:23
-
-
Save davestewart/64fcdf787937a1a98b7233948dc9f158 to your computer and use it in GitHub Desktop.
Gits for medium article: https://medium.com/p/1b2fee1721ec
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
// collection.js | |
export function forEach (arr, callback) { ... } | |
export function map (arr, callback) { ... } | |
export function get (arr, id, key = 'id') { ... } | |
export function getIndex (arr, id, key = 'id') { ... } | |
export function add (arr, item, index = -1) { ... } | |
export function update (arr, id, values) { ... } | |
export function move (fromArr, id, toIndex, toArr = fromArr) { ... } | |
export function moveByIndex (fromArr, fromIndex, toIndex, toArr = fromArr) { ... } | |
export function remove (arr, id) { ... } |
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
import { move } from '@/common/utils/collection' | |
function onDragDrop (fromIndex, toIndex) { | |
move(this.data.bookmarks, fromIndex, toIndex) | |
} |
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
export default class Window { | |
constructor (data) { | |
this.title = data.title | |
this.tabs = data.tabs | |
} | |
moveTab (from, to) { ... } | |
} | |
const window = new Window(data) | |
window.moveTab(1, 5) | |
const tabs = window.tabs |
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
// Window.js | |
// additional code omitted for clarity | |
import { | |
get, | |
add, | |
update, | |
move, | |
remove | |
} from '@/common/utils/collection' | |
export default class Window { | |
constructor (data = {}) { ... } | |
updateTab (info) { | |
return update(this, info) | |
} | |
getTab (tabId) { | |
return get(this.tabs, tabId) | |
} | |
addTab (info, index = -1) { | |
return add(this.tabs, Tab.create(info), index) | |
} | |
moveTab (tabId, toIndex) { | |
return move(this.tabs, tabId, toIndex) | |
} | |
removeTab (tabId) { | |
return remove(this.tabs, tabId) | |
} | |
} |
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
export default class Window { | |
static moveTab (tabs, from, to) { ... } | |
constructor (data) { | |
this.title = data.title | |
this.tabs = data.tabs | |
} | |
} | |
Window.moveTab(data.tabs, 1, 5) |
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
export default class Window { | |
constructor (data) { | |
this.title = data.title | |
this.tabs = data.tabs | |
} | |
moveTab (from, to) { ... } | |
} | |
function moveTab (tabs, from, to) { ... } | |
moveTab(data.tabs, 1, 5) |
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
export default class Window { | |
constructor (data) { | |
this.title = data.title | |
this.tabs = data.tabs | |
} | |
reorder (from, to) { | |
reorder(this.tabs, from, to) | |
} | |
} | |
function reorder (tabs, from, to) { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment