Skip to content

Instantly share code, notes, and snippets.

@vangheem
Created Sep 22, 2016
Embed
What would you like to do?
/* globals define */
define(function(){
'use strict';
var REGISTERED = {};
var register = function(name, config){
REGISTERED[name] = config;
};
var scan = function(baseDoc){
if(!baseDoc){
baseDoc = document;
}
for(var patternName in REGISTERED){
var pattern = REGISTERED[patternName];
baseDoc.querySelectorAll(pattern.selector).forEach(function(el){ // jshint ignore:line
if(el.patternInstance){
return;
}
el.patternInstance = pattern.init(el);
});
}
};
var get = function(name){
return REGISTERED[name];
};
return {
register: register,
scan: scan,
get: get
};
});
@thet

This comment has been minimized.

Copy link

@thet thet commented Sep 22, 2016

Awesome implementation of the Patternslib scanner! If you don't need inside-out pattern initialization and options parsing, this is it.

This is the original implementation, by the way: https://github.com/Patternslib/Patterns/blob/master/src/core/registry.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment