Last active
November 30, 2018 06:33
-
-
Save tungd/8282155 to your computer and use it in GitHub Desktop.
Revisions
-
tungd revised this gist
Apr 29, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ !function(window, React) { var domReady = false, registry = {}, queue = []; window.ReactHelper = { -
tungd revised this gist
Jan 11, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ }, initComponent: function(name) { var props, selector = '[react-component="'+name+'"],[data-react-component="'+name+'"]'; document.querySelectorAll(selector).forEach(function(node) { -
tungd revised this gist
Jan 11, 2014 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,9 +33,7 @@ registry[name] = constructor; queue.push(name); if (domReady) this.initComponents(); }, initComponent: function(name) { @@ -44,7 +42,7 @@ document.querySelectorAll(selector).forEach(function(node) { props = node.getAttribute('react-props') || node.getAttribute('data-react-props') || 'null'; React.renderComponent(registry[name](JSON.parse(props)), node); }) -
tungd revised this gist
Jan 11, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,14 +46,14 @@ props = node.getAttribute('react-props') || node.dataset['reactProps'] || 'null'; React.renderComponent(registry[name](JSON.parse(props)), node); }) } }; window.addEventListener('DOMContentLoaded', function() { domReady = true; ReactHelper.initComponents(); }); }(window, window.React); -
tungd revised this gist
Jan 11, 2014 . 1 changed file with 31 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,29 +14,46 @@ !function(window, React) { var DOMReady = false, registry = {}, queue = []; window.ReactHelper = { initComponents: function() { for (var i = 0; i < queue.length; i += 1) { this.initComponent(queue[i]) } }, forceInitComponents: function() { queue = queue.concat(Object.keys(registry)); this.initComponents(); }, register: function(name, constructor) { registry[name] = constructor; queue.push(name); if (domReady) { this.initComponents(); } }, initComponent: function(name) { var selector = '[react-component="'+name+'"],[data-react-component="'+name+'"]'; document.querySelectorAll(selector).forEach(function(node) { props = node.getAttribute('react-props') || node.dataset['reactProps'] || 'null'; React.renderComponent(registry[name](JSON.parse(props)), node) }) } } window.addEventListener('DOMContentLoaded', function() { domReady = true; ReactHelper.initComponents(); }) }(window, window.React); -
tungd created this gist
Jan 6, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ /** * react-helper.js * * Helper for Facebook's React UI Library. Add support for declare * component on DOM (similar to AngularJS Directive). * * Usage: * - Register a component: * ReactHelper.register('MyComponent', MyComponent) * - Declare the DOM node: * <div react-component="MyComponent" react-props="{'name':'value'}" * - There is no step 3! */ !function(window, React) { var registry = {} window.ReactHelper = { register: function(name, constructor) { registry[name] = constructor }, initComponents: function() { var i, name, props, selector, names = Object.keys(registry) for (i = 0; i < names.length; i += 1) { name = names[i] selector = '[react-component="'+name+'"],[data-react-component="'+name+'"]' document.querySelectorAll(selector).forEach(function(node) { props = node.getAttribute('react-props') || node.dataset['reactProps'] || 'null' React.renderComponent(registry[name](JSON.parse(props)), node) }) } } } window.addEventListener('DOMContentLoaded', window.ReactHelper.initComponents) }(window, window.React);