-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
71 lines (59 loc) · 2.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// defaults from http://include-media.com/documentation/#variable-breakpoints
exports.breaks = {
phone: 320,
tablet: 768,
desktop: 1024
}
exports.sync = function (store, breakjs, breaks) {
patchStore(store)
var commit = store.commit || store.dispatch
// Init BreakJS
// breakjs is only useful to use as the return
// value of its init function, hence overwrite it
breakjs = breakjs(breaks || exports.breaks)
function setBreak() {
var breakpoint = {
breakjs: breakjs,
current: breakjs.current(),
is: {},
atMost: {},
atLeast: {},
lessThan: {},
}
breakjs.breakpoints.forEach(function (value, index, array) {
breakpoint.atLeast[value.name] = breakjs.atLeast(value.name)
breakpoint.atMost[value.name] = breakjs.atMost(value.name)
breakpoint.is[value.name] = value.name === breakpoint.current
breakpoint.lessThan[value.name] = !breakjs.atLeast(value.name)
})
commit('breakpoint/BREAKPOINT_CHANGED', breakpoint)
}
// record the initial breakpoint
setBreak()
store.state.breakpoint.breakjs.addChangeListener(setBreak)
}
function applyMutationState (store, state) {
// support above 2.0
if (store.hasOwnProperty('_committing')) {
return store._committing = state
}
return store._dispatching = state
}
function patchStore (store) {
// add state
var set = store._vm.constructor.set
applyMutationState(store, true);
set(store.state, 'breakpoint', {})
applyMutationState(store, false);
var breakpointModule = {
mutations: {
'breakpoint/BREAKPOINT_CHANGED': function (state, breakpoint) {
set(store.state, 'breakpoint', breakpoint)
}
}
}
// add module
if (store.registerModule) { store.registerModule('breakpoint', breakpointModule) }
else if (store.module) { store.module('breakpoint', breakpointModule) }
else { store.hotUpdate({ modules: { breakpoints: breakpointModule } }) }
}