Skip to content

Instantly share code, notes, and snippets.

View teyfix's full-sized avatar

Halil Teyfik teyfix

  • Istanbul, Turkey
View GitHub Profile
@teyfix
teyfix / props.jsx
Created June 23, 2021 05:32
react - using props
const HelloWorld = () => {
const [show, setShow] = useState(false);
return (
<section>
<h1>Merhaba dünya!</h1>
<GoodMorning show={show} />
<button onClick={() => setShow(!show)}>Merhaba!</button>
</section>
);
@teyfix
teyfix / useState.jsx
Last active June 23, 2021 05:32
react - use state
const HelloWorld = () => {
const [show, setShow] = useState(false);
return (
<section>
<h1>Merhaba dünya!</h1>
{show ? <p>Günaydın.</p> : null}
<button onClick={() => setShow(!show)}>Merhaba!</button>
</section>
);
@teyfix
teyfix / helloWorld.jsx
Last active June 23, 2021 05:32
react - hello world
const HelloWorld = () => (
<section>
<h1>Merhaba dünya!</h1>
</section>
);
ReactDOM.render(
HelloWorld,
document.getElementById('root'),
);
@teyfix
teyfix / appLogin.js
Last active June 21, 2021 19:18
vuex - login component
Vuex.component('app-login', {
template: `
<section>
<header>
<h1>Giriş yap</h1>
</header>
<main v-if="user">
<p>{{ user.username }} olarak giriş yapıldı</p>
</main>
@teyfix
teyfix / login.js
Last active June 21, 2021 19:05
vuex - logging user in with an action
const store = Vuex.Store({
state: {
user: null,
},
mutations: {
setUser(state, user) {
state.user = user;
},
},
actions: {
@teyfix
teyfix / authorize.js
Created June 21, 2021 19:01
vuex - authorizing user
const authorize = async (username, password) => {
const response = await fetch('/login', {
method: 'post',
body: {
username,
password,
},
});
const session = await response.json();
@teyfix
teyfix / setUser.js
Created June 21, 2021 18:54
vuex - setting user info
const store = Vuex.Store({
state: {
user: null,
},
mutations: {
setUser(state, user) {
state.user = user;
},
},
});
@teyfix
teyfix / initialState.js
Created June 21, 2021 18:51
vuex - initial state
const store = Vuex.Store({
state: {
user: null,
},
});
@teyfix
teyfix / usingReplaySubject.js
Created June 20, 2021 12:38
rxjs - using replay subject
const user = new ReplaySubject(1);
authorize(session => user.next(session.user));
@teyfix
teyfix / usingBehaviorSubject.js
Created June 20, 2021 12:38
rxjs - using behavior subject
const fibonacci = new BehaviorSubject(1);
fibonacci.next(1);
fibonacci.next(2);
fibonacci.next(3);
fibonacci.next(5);
fibonacci.next(8);
console.log(fibonacci.value);