Skip to content

Instantly share code, notes, and snippets.

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mikhail Davydov <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@martinandersen3d
martinandersen3d / 1) Main.blade.php
Created April 26, 2018 07:38 — forked from jacurtis/1) Main.blade.php
Laravel 5.4 Components & Slots
<!-- This is the main Blade file that you want your components to show up in -->
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<?php
/**
* kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
* Copyright (C) 2002, 2003, 2005 Ulf Harnhammar
*
* This program is free software and open source software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
@martinandersen3d
martinandersen3d / wordpress plugin post request form.php
Last active February 1, 2023 22:51
wordpress plugin post request form
//-----------------------Intro - most important:
// wp-content/themes/evolve/functions.php
function funkyMonky() {
// Handle request then generate response using echo or leaving PHP and using HTML
echo "hi";
}
add_action('admin_post_takeaway_settings_order','funkyMonky');
@martinandersen3d
martinandersen3d / laravel collection vs code snippet.json
Last active January 15, 2019 09:57
laravel collection vs code snippet
// in project folder: "\.vscode\snippets\vue.json"
// Put snippets at .vscode/snippets/<languageId>.json
// For example, .vscode/snippets/javascript.json
// extension: project snippet: https://github.com/rebornix/vscode-project-snippet
{
"all": {
"prefix": "all()",
"body": [
".all($1)"
],
@martinandersen3d
martinandersen3d / Has all.js
Created December 12, 2017 04:16
Compare two arrays, arrA must have all the items that is in arrB
/**
* Returns TRUE if the first specified array contains all elements
* from the second one. FALSE otherwise.
*
* @param {array} superset
* @param {array} subset
*
@martinandersen3d
martinandersen3d / vue draggable nested tree.vue
Last active December 8, 2017 00:36
vue draggable nested tree [Solution & Working, vue 2.x]
// PARENT -----------------------------------------------------
<template>
<div>
<devinfo :code='$data' name='treeParent' ></devinfo>
<b-field label="Add Page">
<input ref='pageTextField' @keyup.enter="addPageFromTextfield" v-model="textfieldvalue">
</b-field>
<treeChild :data="data"></treeChild>
@martinandersen3d
martinandersen3d / uuid.js
Created December 3, 2017 21:09 — forked from antonioaguilar/uuid.js
Generate UUID in Browser
function UUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
@martinandersen3d
martinandersen3d / LICENSE
Created December 2, 2017 21:21 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: