Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Menteur
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PLN
Menteur
Commits
02b95030
Unverified
Commit
02b95030
authored
5 years ago
by
PLN (Algolia)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: Begin store implem, display last 20 messages
parent
24645257
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
35 deletions
+33
-35
App.vue
client/src/App.vue
+11
-25
Sockets.vue
client/src/Sockets.vue
+13
-8
HelloWorld.vue
client/src/components/HelloWorld.vue
+9
-2
No files found.
client/src/App.vue
View file @
02b95030
<
template
>
<div
id=
"app"
>
<HelloWorld
msg=
"Salut Menteur !"
/>
<HelloWorld
/>
<Sockets/>
<div
id=
"game"
>
<label
for=
"messages"
>
Choose a message:
</label>
...
...
@@ -18,35 +18,15 @@
<
script
>
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
'es6-promise/auto'
// Needed for Promise polyfill
import
VueSocketIO
from
'vue-socket.io'
import
Vuex
,
{
mapGetters
,
mapMutations
}
from
'vuex'
;
import
HelloWorld
from
"./components/HelloWorld"
;
import
Sockets
from
"./Sockets"
;
import
{
store
}
from
'./vuex-store'
Vue
.
use
(
Vuex
);
const
store
=
new
Vuex
.
Store
({
state
:
{
count
:
0
},
mutations
:
{
increment
(
state
)
{
state
.
count
++
},
decrement
(
state
)
{
state
.
count
++
}
}
// TODO: Use actions for VueX-SocketIO integration?
// actions: {
// "
<
ACTION_PREFIX
><
EVENT_NAME
>
"() {
// // do something
// }
// }
});
Vue
.
use
(
new
VueSocketIO
({
debug
:
true
,
connection
:
'http://localhost:9042'
,
...
...
@@ -61,6 +41,7 @@
export
default
{
name
:
"App"
,
store
:
store
,
components
:
{
HelloWorld
,
Sockets
...
...
@@ -70,11 +51,16 @@
message
:
"WAITING"
}
},
computed
:
{
...
mapGetters
([
'isConnected'
,
'name'
,
'socketMessage'
])
},
methods
:
{
sendMessage: function(message) {
sendMessage
:
function
(
message
)
{
console
.
log
(
"User wants to send"
,
message
);
this
.
$socket
.
emit
(
"message"
,
message
);
}
},
...
mapMutations
([
'setName'
]),
// ...mapActions(['setNumberToRemoteValue']),
}
};
...
...
This diff is collapsed.
Click to expand it.
client/src/Sockets.vue
View file @
02b95030
...
...
@@ -2,9 +2,16 @@
<div>
<p
v-if=
"isConnected"
>
We're connected to the server!
</p>
<p
v-if=
"!isConnected"
>
We're not connected yet...
</p>
<div
v-if=
"socketMessage != null"
>
<p>
Message from server: "
{{
socketMessage
}}
"
</p>
<div
v-if=
"socketMessages.length >= 1"
>
<p>
Messages from server"
</p>
<ul
id=
"messages"
>
<li
v-for=
"message in socketMessages.slice(-20)"
:key=
"message"
>
{{
message
}}
</li>
</ul>
</div>
<button
@
click=
"pingServer()"
>
Ping Server
</button>
<button
@
click=
"logOn()"
>
LogOn
</button>
<button
@
click=
"logOff()"
>
LogOff
</button>
...
...
@@ -16,7 +23,7 @@
data
()
{
return
{
isConnected
:
false
,
socketMessage
:
null
socketMessage
s
:
[]
}
},
...
...
@@ -29,13 +36,11 @@
disconnect
()
{
this
.
isConnected
=
false
;
console
.
log
(
"logoff"
);
},
customEmit
:
function
(
data
)
{
console
.
log
(
'this method was fired by the socket server. Data:'
,
data
);
this
.
socketMessages
=
[];
},
// Fired when the server sends something on the "messageChannel" channel.
messageChannel
(
data
)
{
this
.
socketMessage
=
data
;
this
.
socketMessage
s
.
push
(
data
)
;
console
.
log
(
"Message received:"
,
data
,
"!"
);
}
},
...
...
@@ -58,7 +63,7 @@
},
logOff
()
{
this
.
$socket
.
ondisconnect
();
this
.
socketMessage
=
null
;
this
.
socketMessage
=
[]
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
client/src/components/HelloWorld.vue
View file @
02b95030
<
template
>
<div
class=
"hello"
>
<h1>
{{
msg
}}
</h1>
<h1>
Salut
{{
this
.
printName
()
}}
!
</h1>
</div>
</
template
>
...
...
@@ -8,7 +8,14 @@
export
default
{
name
:
"HelloWorld"
,
props
:
{
msg
:
String
name
:
String
},
methods
:
{
printName
()
{
let
name
=
this
.
$store
.
name
;
console
.
log
(
"Saying hello to "
,
name
);
return
name
}
}
};
</
script
>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment