Skip to content

Commit

Permalink
fix: simplify instance args signature
Browse files Browse the repository at this point in the history
  • Loading branch information
rafegoldberg committed Dec 27, 2021
1 parent 43907e2 commit 6b4c8f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/classy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export function classy(...args) {
* can be reused for its scope and BEM root!
*/
if (new.target) {
const { bem = "", classes = {}, scope = {} } = args?.[0] || {};
let scope, namespace;
if (typeof args[0] === "string") [namespace, scope] = args;
else [scope, namespace] = args;
const { bem = namespace, classes = {} } = scope || {};
return (...selectors) => {
const cn = classy({ bem, ...scope, ...classes }, selectors);
return cn || scope?.[bem] || bem;
Expand Down
10 changes: 4 additions & 6 deletions src/useClassy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import { classy } from "../classy";
* @returns {String} a normalized list of class selectors
*/
export const useClassy = (scope, namespace) => {
const bem = useCallback(() => {
return new classy({
classes: scope,
bem: namespace,
});
}, [scope, namespace]);
const bem = useCallback(
() => new classy(scope, namespace),
[scope, namespace]
);
return useMemo((...args) => bem(...args), [bem]);
};

Expand Down

0 comments on commit 6b4c8f8

Please sign in to comment.