about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/react_helpers.js
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2018-01-05 18:29:08 -0500
committerGitHub <noreply@github.com>2018-01-05 18:29:08 -0500
commitfaf20eeaa4c6f48a97a41a948ed29e734c8c4f5e (patch)
treeda0b88781650d514c209641fc6af7cbb921afe0b /app/javascript/flavours/glitch/util/react_helpers.js
parentf41b33eb0177b23bd72fede7df94af43da0c7c6b (diff)
parentd7ce339c2e33a5607c21d3eff316669cff9c6ea3 (diff)
Merge pull request #293 from glitch-soc/compose-refactor
Compose refactor
Diffstat (limited to 'app/javascript/flavours/glitch/util/react_helpers.js')
-rw-r--r--app/javascript/flavours/glitch/util/react_helpers.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/react_helpers.js b/app/javascript/flavours/glitch/util/react_helpers.js
new file mode 100644
index 000000000..082a58e62
--- /dev/null
+++ b/app/javascript/flavours/glitch/util/react_helpers.js
@@ -0,0 +1,21 @@
+//  This function binds the given `handlers` to the `target`.
+export function assignHandlers (target, handlers) {
+  if (!target || !handlers) {
+    return;
+  }
+
+  //  We just bind each handler to the `target`.
+  const handle = target.handlers = {};
+  Object.keys(handlers).forEach(
+    key => handle[key] = handlers[key].bind(target)
+  );
+}
+
+//  This function only returns the component if the result of calling
+//  `test` with `data` is `true`.  Useful with funciton binding.
+export function conditionalRender (test, data, component) {
+  return test(data) ? component : null;
+}
+
+//  This object provides props to make the component not visible.
+export const hiddenComponent = { style: { display: 'none' } };