Skip to content

Instantly share code, notes, and snippets.

@arthur-abogadil
Last active July 6, 2020 07:33
Show Gist options
  • Save arthur-abogadil/59bfbb353161dcc1594f4a6df0b28771 to your computer and use it in GitHub Desktop.
Save arthur-abogadil/59bfbb353161dcc1594f4a6df0b28771 to your computer and use it in GitHub Desktop.
for cc.
// Im not able to show some of the most important things ive written for my last customizer project
// as im bound by an NDA, but here i can present some simple things in the utilities libraries
// that ive devised and used that helped
// the architecture of the projects ive created much cleaner
// This is a very simple js idiom i developed early in the development
// of the customizer, it basically just uses the jquery rest call function
ub.loader = function (url, object_name, cb) {
$.ajax({
url: url,
type: "GET",
dataType: "json",
crossDomain: true,
contentType: "application/json",
headers: {"accessToken": (ub.user !== false) ? atob(ub.user.headerValue) : null},
success: function (response) {
cb(response[object_name], object_name);
}
});
};
// The interesting thing here is the cb parameter, which is the callback function parameter
// it helped in two things for all the API calls i need to do for the project,
//
// 1. It's a cleaner way to make the call, specify the endpoint, and the structural destination of
// the data object
// 2. Be able to specify a generic or specific preprocessor function that can check the consistency of the data
// and more importantly transform it to a cleaner structure at the early stage while the backend requirements is not
// yet final and is very mallable due to frequent changes while the architectural decisions is
// is constantly being refined as we learned new ways to improve how we handle things.
//
// For example here, i was able to specify a preprocessor that only processes the data after the prioritized data is loaded first
// the ability to do this is important for efficiency reasons e.g. just loading the first font used in the uniform and not the entire library
ub.loader(ub.current_material.taggedStyles, 'taggedStyles', ub.callBackPostLoad);
// or just use the generic loads such as below
ub.loader(ub.current_material.colorsUrl, 'colors', ub.callback);
// or be able to just create an anonymous function in place
ub.funcs.getColorsSets = function (name) {
var colors = [];
var _url = window.ub.config.api_host + '/api/colors_sets';
ub.loader(_url, 'colors_sets', function (result) {
var colorSet = _.find(result, { name: name, active: 1 });
_.map(JSON.parse(colorSet.colors), function(color) {
// ... code deleted intentionally
});
});
return colors;
}
// Lots of the idioms i created in the whole project was similar later to how GraphQl and and Axios rest library approached bulding their respective libraries
// This went on with the whole project like how i made a generic function to create Player names, but later being able to use
// that to create mascots and even integrate third party libraries, that scope of which i wont be able to put in here
// This is much inline to ruby principles, DRY, and KISS, even YAGNI for some others to solve premature optimization or perfecting
// things too early.
//
// I really wanted to show here the more advanced stuff like being able to implement multiple sports very fast
// because this is one of the main architectural designs im really proud with the customizer, but can't because of NDA's.
// But basically, the previous customizers are sport specific, meaning you need to create a new customizer for each sport, but
// for the one i did, you can see if you check it, it even now have a face mask customizer.
/// Here's another idiom i actually learned from ruby which i adopted to js, which is constructing collections
ub.funcs.transformPatterns = function (inputPatternsObject) {
var _inputPatternsObject = _.filter(inputPatternsObject, function (pattern) {
var _blankPatternID = ub.config.blankPatternID;
var _blockPatternOptions = JSON.parse(pattern.block_pattern_options);
var _sports = JSON.parse(pattern.sports);
var _sportOk = _.contains(_sports, ub.config.sport);
var _neckOptionOk = _.contains(_blockPatternOptions, ub.config.option) ||
_blockPatternOptions === null ||
(typeof _blockPatternOptions === "object" && _blockPatternOptions[0] === "");
/// .... Deleted intentionally
return (
(
_neckOptionOk &&
_sportOk &&
pattern.asset_target === ub.config.asset_target
) ||
parseInt(pattern.id) === parseInt(_blankPatternID)
);
});
var _container = [];
_.each(_inputPatternsObject, function (_object, index) {
var sort_id = index + 1;
if (_object.name === 'Blank') { sort_id = 0; }
_newObject = {
sortID: sort_id,
id: _object.id,
active: _object.active,
name: _object.name,
code: _object.name.toCodeCase(),
icon: _object.thumbnail_path,
sports: JSON.parse(_object.sports),
blockPatternOptions: JSON.parse(_object.block_pattern_options),
layers: [],
asset_target: _object.asset_target,
brand: _object.brand,
};
var _patternProperties = JSON.parse(_object.pattern_properties);
_.each(_patternProperties, function (_patternProperty) {
var _layer = {
default_color: ub.funcs.getHexColorByCode(_patternProperty.default_color),
layer_no: parseInt(_patternProperty.layer),
filename: _patternProperty.file_path,
team_color_id: _patternProperty.team_color_id,
};
_newObject.layers.push(_layer);
});
_container.push(_newObject);
ub.data.patterns = {
items: _container,
}
});
};
// Here's two previous ruby rails project i did,
// Genielets is a Landlord app for managing and renting his/her properties similar to airbnb, albeit much more simpler
https://bitbucket.org/arthur_abogadil/genielets/commits/
// this one is a custom carpentry work site a CRM type of application, the other newer rails projects i have is also bound under a non-disclosure and a non-compete so i cant say it here
https://bitbucket.org/arthur_abogadil/allenscabinets-timetracker/commits/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment