question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@clone handle to copy/clone properties

See original GitHub issue

After start reading this thread from @adamwathan I got to wonder if something could be done like this.

So @adamwathan points out a missing possibility to copy out the properties from a class rather than extending it, helping out the possibility of creating utilities and inject them in components easily, "mixin’ free some of the most popular CSS frameworks out there.

I’ve found that this feature was being addressed back in 2015 at #1852 , but it was with another a purpose (maybe that why it was closed?)


So normally we @extend SASS like this:

.foo {
    @extend .baz;
    background-color: green;
}
.bar {
    color: blue;
}
.baz {
    color: red;
}

That outputs the the following CSS:

.foo {
    background-color: green;
}
.bar {
    color: blue;
}
.baz, .foo {
    color: red;
}

But what if we can @clone another class properties, pretty much like LESS?

.foo {
    @clone .baz; // or @copy .baz;
    background-color: green;
}
.bar {
    color: blue;
}
.baz {
    color: red;
}

That the will output this:

.foo {
    color: red;
    background-color: green;

}
.bar {
    color: blue;
}
.baz {
    color: red;
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:29 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
mindplay-dkcommented, Aug 6, 2017

If you want to copy chunks of properties, well, that’s what mixins are for.

Having to rewrite (or hack) third-party (S)CSS and wrap everything in mixins isn’t practical.

Adding another concept that’s between those two would just muddy the waters.

That’s your opinion, but people nevertheless seek this feature, and it’s a key reason why some choose LESS instead.

For one, the precedence issues caused by @import in my opinion are somewhat undeniable.

How about extending @include to allow something like @include .foo?

Or think of some other way to make this functionality (or something even better) available.

Simply dismissing the feature entirely seems a little too easy - people often ask for this feature, in fact a few developers on our team want to go back to LESS for this.

I think there is a real need here, that is not covered by @extend - can’t we think of some way to address that need without “violating CSS semantics”?

5reactions
mindplay-dkcommented, Aug 10, 2017

It’s easy to define a mixin and use that to define the utility class

It’s not easy to rewrite or hack all third-party CSS (or SCSS) files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Cloning - Manual - PHP
An object copy is created by using the clone keyword (which calls the object's __clone() method if possible). $copy_of_object = clone $object;. When...
Read more >
Methods for deep cloning objects in JavaScript - LogRocket Blog
There are several ways to shallow clone objects in JavaScript, but deep cloning objects is trickier. We highlight several methods to do so....
Read more >
Cloning any javascript object by copying all own properties
This will create all the properties present in the original object onto the clone, as well as their values. Now the problem is,...
Read more >
JS Copy an Object – How to Clone an Obj in JavaScript
An alternative to the spread operator is the Object.assign() method. You use this method to copy the values and properties from one or...
Read more >
Java Object clone() Method - Cloning in Java - DigitalOcean
Cloning is the process of creating a copy of an Object. ... (Employee) emp.clone(); // Check whether the emp and clonedEmp attributes are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found