Skip to content

Instantly share code, notes, and snippets.

View betocantu93's full-sized avatar
🏠
Working from home

Alberto Cantú Gómez betocantu93

🏠
Working from home
View GitHub Profile
@betocantu93
betocantu93 / bucket.js
Last active March 22, 2019 22:59
Bucket Storage. Fast util for persisting and retrieving from local or session storage it's also bucket oriented
const DEFAULT_BUCKET_NAME = "general";
const DEFAULT_TYPE = "local";
/*
* Storage class should be used as follow:
*
* @param string "session" || "local" //default local
* @param string Bucket Name, where following objects will be stored, it's like a namespace.
*
* const storage = Storage("local", "tables");
copyToNoneLocal: task(function* (draft, ignoreModel = null, level = 0) {
try {
let draftType = draft.modelName;
let modelType = draftType.replace('-local', '');
let model = this.store.createRecord(modelType);
let mixedProperties = [];
let relationships = [];
let properties = []
import Mixin from '@ember/object/mixin';
import Ember from 'ember';
import { singularize } from 'ember-inflector';
export default Mixin.create({
// ember temporary ids
_tempIds: {},
@betocantu93
betocantu93 / dynamic-model-initializers-model.js
Last active April 7, 2020 23:40
Reopen models in runtime
import DS from "ember-data";
import { computed } from "@ember/object";
import { assert } from "@ember/debug";
const { Model } = DS;
Model.reopenClass({
/**
* The following props are overrided, since per definition
* they are sealed props defined in
@betocantu93
betocantu93 / globals.js
Last active June 22, 2020 20:03
Adds some runtime globals for making Ember.js developing a breeze
//instance-initializers/globals.js
export function initialize(application) {
let { environment } = application.resolveRegistration('config:environment');
if (environment !== "production") {
/**
This basically exposes the application, pretty useful because
you can use stuff like this from the console.
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
@betocantu93
betocantu93 / app-shell.js
Created September 17, 2020 18:15
Clean the dom when ember root view is ready
export function initialize(appInstance) {
if (typeof FastBoot === 'undefined') {
let originalDidCreateRootView = appInstance.didCreateRootView;
appInstance.didCreateRootView = function() {
let elements = document.querySelectorAll(appInstance.rootElement + ' #app-shell');
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
element.parentNode.removeChild(element);
@betocantu93
betocantu93 / machine.js
Last active September 18, 2020 16:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@betocantu93
betocantu93 / machine.js
Created October 20, 2020 16:14
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@betocantu93
betocantu93 / machine.js
Last active January 13, 2021 16:44
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions