Skip to content

Instantly share code, notes, and snippets.

View DanielDornhardt's full-sized avatar

Daniel Dornhardt DanielDornhardt

  • Limassol, Cyprus
  • 09:56 (UTC +02:00)
View GitHub Profile
@DanielDornhardt
DanielDornhardt / plugin-removeAsyncCodeFromClient.js
Created October 12, 2023 14:00
Babel Plugin to De-Asyncify Meteor Client Code
/**
* This is a babel plugin to de-asyncify MeteorJS client code.
*
* Note: This is currently experimental.
*
* This is primarily meant to restore the full reactivity of the Tracker module by removing the Async code necessary
* for the server, and instead calling synchronous versions of the same which work on the client because of minimongo being able
* to work synchronously.
*
* It does the following transformations:
@DanielDornhardt
DanielDornhardt / plugin.js
Created October 2, 2023 12:30
Meteor Async Transition: Babel Plugin to keep Tracker Computation alive after "await"s
/**
* This babel plugin tries to alleviate problems with Meteor Trackers' autoruns & reactive code
* when used together with async / await.
*
* We'll store a copy of the current Tracker.currentComputation inside each async function in your code (!!!)
* and then we'll restore it *after* each await call, but only in the current functions' context... it's complicated :) .
*
* But this seems to allow us, in short, to keep the code reactive even after multiple - and nested - await's.
*
* It's maybe not done, but it should be a good proof-of-concept for now.
@DanielDornhardt
DanielDornhardt / asyncHelpers.html
Last active October 5, 2023 10:20
Meteor Blaze asyncHelpers.html - helper templates for working with ASYNC values in Blaze Templates
<!--
Display potentially async data source results in the template. Unsafe Content / HTML will be escaped like with regular {{ someValue }} blaze syntax.
Use like this:
{{> await someValue}}
-->
<template name="await">{{#let value=.}}{{value}}{{/let}}</template>
<!--
Display potentially async data source results in the template. Unsafe Content / HTML will NOT be escaped, similar to using the triple bracket {{{ someValue }}} blaze syntax.
Use like this:
@DanielDornhardt
DanielDornhardt / gist:0f3628c898b946a7cc4d
Created April 8, 2015 22:08
Saving additional info to images using collectionFS on the server
if Meteor.isServer
crypto = Npm.require 'crypto'
# find our "code" dir / the directory outside of meteor
pathArr = process.env.PWD.split '/'
pathArr.pop()
filesBasePath = pathArr.join '/'
filesBasePath = filesBasePath + '/uploads/example/'
fsOptionsOriginalSizeJpg =
@DanielDornhardt
DanielDornhardt / gist:c3f4195bed9afacc2ddf
Created March 27, 2015 16:27
Meteor EasySearch case insensitive substring search query
query: function(searchString) {
var field, selector, stringSelector;
selector = {};
field = this.field;
stringSelector = {
'$regex': '.*' + searchString + '.*',
'$options': 'i'
};
if (_.isString(field)) {
selector[field] = stringSelector;
@DanielDornhardt
DanielDornhardt / gist:39b5fb5f9f12d9390f25
Last active August 29, 2015 14:14
Autoform - How could I make form fields visible depending on other values in the form?

How could I make form fields visible depending on other values in the form?

Eg. in the following example I'd like to see the "afQuickField name=vehicle_type_car_num_wheels" only if the selected vehicleType would be 'car' and "afQuickField name=vehicle_type_plane_num_wings" only if vehicleType would be "plane".

The schema could look like this:

vehicleType:
  type: String
  label: 'Type of Vehicle'

allowedValues: ['car', 'plane']