Use Nested class with different file in css module and scss? - sass

I wanted to make nested class with class from other file in css module
Assume that there is two file
FIle A
.a{
}
File B
.b{
}
then I want to use in nested b class in A file like
.a{
.b{
}
}
How can I acheive it? I'm using scss
Actually A is parent class and B is child
so I want to style b when A is Parent.

Related

How to let the editor know about dynamic properties?

The properties are loaded dynamically in CodeIgniter.
How to let the editor know it should be allowed?
If you know the full list of dynamic properties you're going to use, you can add them as #property docblock annotations on the class, in the format #property type name description.
The classic use case for this is where the class implements __get to lazy-load data, or in your case dependencies injected by the framework.
/**
* #property FormValidation form_validation Form validation object injected by CodeIgniter
*/
class Example {
public function foo() {
$this->form_validation->set_rules('blah', 'blah', 'blah');
}
}
Note that these magic properties are assumed to be inherited, and public, so the following will not show warnings:
// Using magic property in child class
class ExampleChild extends Example {
public function somethingElse() {
$this->form_validation->set_rules('something', 'else', 'entirely');
}
}
// Using magic property from outside class
$foo = new Foo;
$fv = $foo->form_validation;

How to properly do an array of classes for a UICollectionView registration?

What I'm attempting to accomplish is this:
I have a bunch of classes, which define different feeds for my home controller. As I swipe left and right, it will show each feed from each class.
Now, I can register each class like this (which works):
collectionView?.register(VideoListView.self, forCellWithReuseIdentifier: VideoListView().getCellId())
collectionView?.register(AlertListView.self, forCellWithReuseIdentifier: AlertListView().getCellId())
Each ListView class inherits a base class called FeedView:
class FeedView: BaseCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
BaseCell just has my init and things I don't want to repeat in each class:
class BaseCell: UICollectionViewCell
What's I'm trying to do is this:
let horizontalViews = [VideoListView, AlertListView]
for hv in horizontalViews{
collectionView?.register(hv.self, forCellWithReuseIdentifier: hv.getCellId())
}
But, what I'm getting are these errors:
Expected member name or constructor call after type name
and
Instance member 'getCellId' cannot be used on type 'FeedView'
Okay, so I change the classes in the array to be like this:
let horizontalViews = [VideoListView(), AlertListView()]
But then I get this error:
Cannot invoke 'register' with an argument list of type '(FeedView,
forCellWithReuseIdentifier: String)'
That is with doing both hv.self and just hv in the register() call.
I'm new to Swift/Xcode development, so any help will be appreciated.
I tried it with Swift classes (String, Int, etc...) and I failed. But, with classes derived with NSObject, which include UIViewControllers you can do it.
The common thing you want is UIViewController. So you can do like this:
var classes: [UIViewController.Type] = []
This means you can add anything of type "A type of UIViewController". From which, all UIViewController types derive.
You want to append something to this array. Try this:
classes.append(YourFirstViewController.self)
classes.append(YourSecondViewController.self)

How to create class variables in a PHPSpec spec file that can be used for all examples in the spec

I have a PHPSpec class with many examples. I want to be able to create class variables in the spec class that can be used by any example function in the class.
Below is a very simplified version:
class ThingImTestingSpec extends ObjectBehavior
{
private $common_variables_array = [
'property_1' => value_1,
'property_2' => 'Value 2'
];
function it_finds_a_common_property()
{
$object_1 = new ConstructedObject;
$this->find_the_common_property($object_1)->shouldReturn($this->common_variables_array['property_1']);
}
}
The issue lies in how PHPSpec (cleverly) instantiates and references the class under test. References to $this in the spec methods actually refer to the test object, not the spec class itself.
But that means that trying to reference class variables using $this->class_variable references class variables on the test object, not the spec.
So. How to create a set of variables in the scope of the spec class itself that can be accessed by the examples at runtime?
Things I've tried:
Placing the class variables within a constructor – still can't be accessed by the examples
Using beConstructedWith – requires altering the class under test just so it can be tested. Not a clean solution.
When the common objects I want to reference are database records, I can reference them by id (or other properties) using Eloquent, building a collection or class object from the Model each time. This works, but is time-consuming, as I need to build the collection or object in every spec function. I'd like to build these collections and objects once, when the spec class is instantiated, and reference them throughout the class.
Things I haven't tried yet:
Creating a third object outside the scope of both the spec class and the class under test to house the universal objects and variables, which can be accessed by the spec class methods (the examples) at runtime. This solution could work, but it adds a layer to the specs that I'd like to avoid if there's a cleaner solution.
NB: I'm not looking for "alternatives" to going about testing in the way outlined above, unless they still suit the broader needs. The example is extremely pared down. In practice, I'm extending LaravelObjectBehavior (https://github.com/BenConstable/phpspec-laravel), creating records in a test database using the spec's constructor via Factory and Faker classes (https://github.com/thephpleague/factory-muffin), and destroying them after the test (League\FactoryMuffin\Facade::deleteSaved() in the spec's destructor). I want to be able to reference objects represented by the Model (and created by FactoryMuffin) in any number of spec functions, so I don't have to recreate these objects and collections in every spec function. And yes, I'm aware that this steps outside the realm of "spec" testing, but when an app is tethered to a model, objects that interact with the data layer are still "speccable", it can be argued.
I'm currently using phpspec 2.2.1 and Laravel 4.2
We currently use PHPSpec v3 in our software. Please use let method to declare common things. Quick example:
<?php
class ExampleSpec extends \PhpSpec\ObjectBehavior
{
private $example; // private property in the spec itself
function let()
{
$this->example = (object) ['test1' => 'test1']; // setting property of the spec
parent::let();
}
function it_works()
{
var_dump($this->example); // will dump: object(stdClass)#1 (1) { ["test1"] => string(5) "test1" }
}
function it_works_here_as_well()
{
var_dump($this->example); // will dump same thing as above: object(stdClass)#1 (1) { ["test1"] => string(5) "test1" }
$this->example = (object) ['test2' => 'test2']; // but setting here will be visible only for this example
}
function it_is_an_another_example()
{
var_dump($this->example); // will dump same thing first two examples: object(stdClass)#1 (1) { ["test1"] => string(5) "test1" }
}
}
Found the answer. Explicitly declare the class variables as static and they can be accessed by the methods in the spec class:
class ThingImTestingSpec extends ObjectBehavior
{
private static $common_variables_array = [
'property_1' => value_1,
'property_2' => 'Value 2'
];
function it_finds_a_common_property()
{
$object_1 = new ConstructedObject;
$this->find_the_common_property($object_1)->shouldReturn($this::$common_variables_array['property_1']);
}
}
This is working for arrays as well as objects that represent database records built using Eloquent, e.g.
class LaravelAppClassImTestingSpec extends LaravelObjectBehavior
{
private static $Order_1;
function __construct()
{
$Order_1 = \Order::find(123);
}
function it_tests_a_thing()
{
//(the method has access to the static class variable via
//$this::$Order_1
}
}

zf2 call a method from a Model in another Model

I have a couple of modules in ZF2 project. Each module has different model classes performing different required functions. Now I have method in a model class of first module which I want to call in the model class of second module. Is it possible to do so? if yes, how?
This should be fairly simple. Firstly you need to include the two modules in your application.config.php
'modules' => array(
'Module1',
'Module2'
)
Then as a very basic example taken from your question:
<?php
namespace Module2\Model;
use Module1\Model\Class1;
class Class2
{
public function doSomething()
{
$class1 = new Class1();
$class1->doSomething();
}
}

How do you share common methods in different grails controllers?

Currently when I need to share a method like processParams(params) between different controllers, I use either inheritance or services.
Both solution has some inconvenients :
With inheritance, you cannot use multiple inheritance which means that you need to have all of your controller utility methods in one place. And also, there is a bug in grails that does not detect any code changes in Base Controller classes in development mode (you need to restart the app)
With services, you don't have access to all injected properties like params, session, flush...
So my question is : is there any other way to use some common methods accessible for multiple controllers ?
One option I like is to write the common methods as a category, then mix it into the controllers as necessary. It gives a lot more flexibility than inheritance, has access to stuff like params, and the code is simple and understandable.
Here's a tiny example:
#Category(Object)
class MyControllerCategory {
def printParams() {
println params
}
}
#Mixin(MyControllerCategory)
class SomethingController {
def create = {
printParams()
...
}
def save = {
printParams()
}
}
Common functionality is a call for a new class, not necessarily common ancestor. The question formulation is missing responsibility statement for it. Needless to say, it's a single responsibility that we create a new class for. I take further decisions basing on class responsibility.
I prefer a hybrid of robbbert's and Jared's answers: I construct extra classes, passing them necessary controller internals as parameters. Sometimes the classes develop from method objects.
Like:
def action = {
def doer = SomeResponsibilityDoer(this.request, this.response)
render doer.action()
}
Not so brief, but lets you get code under tests and keep coupling low.
As SomeResponsibilityDoer is only going to have couple of fields - request an response - it's not a big deal constructing it with every request.
It's also not a big deal having SomeResponsibilityDoer not reloaded on controller change in dev, because:
Initially, you can declare it in some of Controller files - it will be reloaded. After you complete it, hopefully it won't change often, so move it to src/groovy.
Even more important, it's faster and better for design to develop under unit tests than under application running and reloading a Contoller.
This doesn't help the restarting in development mode issue you have, but it's the way I've solved this problem. It's ugly and probably not good practice, but I factor common code into classes as closures. Then I can do something like:
new ControllerClosures().action(this)
and from with in the controllerClosures class
def action={
it.response.something
return [allYourData]
}
You can use the Delegation design pattern:
class Swimmer {
def swim() { "swimming" }
}
class Runner {
def run() { "running" }
}
class Biker {
def bike() { "biking" }
}
class Triathlete {
#Delegate Swimmer swimmer
#Delegate Runner runner
#Delegate Biker biker
}
def triathlete = new Triathlete(
swimmer: new Swimmer(),
runner: new Runner(),
biker: new Biker()
)
triathlete.swim()
triathlete.run()
triathlete.bike()
In case of a controller, assign the helper class directly at the instance field (or in the nullary constructor):
class HelperClass {
def renderFoo() { render 'foo' }
}
class FooController {
private #Delegate HelperClass helperClass = new HelperClass()
def index = { this.renderFoo() }
}
The delegate's type information gets compiled into the containing class.
You can write all the common method in commonService
and use that service to envoke commmon method

Resources