Skip to content

Instantly share code, notes, and snippets.

View kstulgys's full-sized avatar
🎯
Focusing

Karolis Stulgys kstulgys

🎯
Focusing
View GitHub Profile
@kstulgys
kstulgys / checkboxOverides.js
Last active October 23, 2019 22:41
checkboxOverides
const checkboxOverides = {
".form-check-label": {
height: "full",
display: "flex",
alignItems: "center",
minHeight: 10
},
".form-check-label span": {
pl: 2
},
import TodosModel from "./TodosModel";
import TodosView from "./TodosView";
import TodosController from "./TodosController";
import PubSub from "./PubSub";
const pubSub = new PubSub();
const model = new TodosModel(pubSub);
const view = new TodosView(document.getElementById("app"), pubSub);
new TodosController(model, view);
export default class PubSub {
constructor() {
this.registry = {};
}
on(evtName, cb) {
this.registry[evtName] = this.registry[evtName] || [];
this.registry[evtName].push(cb);
}
export default class TodosController {
constructor(model, view) {
this.model = model;
this.view = view;
this.init();
}
init() {
this.view.createView();
this.setEventListeners();
export default class TodosView {
constructor(wrapper, pubSub) {
this.wrapper = wrapper;
this.pubSub = pubSub;
this.cashe = {};
}
createView() {
this.wrapper.insertAdjacentHTML("afterbegin", this.renderUI());
this.cashe.todosList = document.querySelector(".todos-list");
export default class TodosModel {
constructor(pubSub) {
this.todos = [
{ title: "clean room", id: 1, done: false },
{ title: "read book", id: 2, done: false },
{ title: "learn classes", id: 3, done: false }
];
this.pubSub = pubSub;
}
@kstulgys
kstulgys / App.js
Last active February 8, 2019 05:10
import Store from "./store/index"
function App() {
const { state, setState } = Store.useStore()
const onInc = () =>
setState(state =>
state.count = state.count + 1
)
@kstulgys
kstulgys / index.js
Last active October 14, 2019 10:53
import React, { useMemo, useContext, createContext } from "react"
import { useImmer } from "use-immer"
const initialState = {
count: 0
}
function makeStore() {
const Context = createContext()
handleChange = (e) => {
const { name, value } = e.target
this.setState((prevState, props) => ({
[name]: value,
}));
const lbm = this.state.kg -(this.state.kg * (this.state.fp / 100))
const bmr = 370 + (21.6 * this.state.lbm)
this.setState((aprevState, props) => ({
lbm,
@kstulgys
kstulgys / another.rb
Last active April 12, 2017 05:40
Project 2: Private Events
<%= form_for(project) do |f| %>
<% if project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(project.errors.count, "error") %> prohibited this project from being saved:</h2>
<ul>
<% project.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>