Skip to content

Contract with ICSS #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TrySound opened this issue Jun 6, 2017 · 7 comments
Open

Contract with ICSS #241

TrySound opened this issue Jun 6, 2017 · 7 comments

Comments

@TrySound
Copy link
Member

TrySound commented Jun 6, 2017

This thread to summarize all contracts between icss plugins

  • postcss-icss-selectors
  • postcss-icss-values
  • postcss-icss-composes

This plugins do not require contracts

  • postcss-icss-import
  • postcss-icss-url
  • postcss-icss-keyframes

Values plugin before selectors and composes plugins

If local identifier already exists :import keys then skip scoping

@value local1 from 'path';
.local1 {}
.local2 { composes: local1; }
.local3 { composes: exported from 'path'; }

/* after values */

:import('path') {
  __local1: local1
}
:export {
  local1: __local1
}
.__local1 {}
.local2 { composes: __local1; }
.local3 { composes: exported from 'path'; }

/* after selectors and compose */

:import('path') {
  __local1: local1;
  __exported: exported;
}
:export {
  local1: __local1;
  local2: __scope__local2;
  local3: __scope__local3;
}
.__local1 {}
.__scope__local2 {}
.__scope__local3 {}

Values plugin after selectors and composes plugin

Values can't be detected in compound exported values

@value local2 from 'path';
.local1 {}
.local2 { composes: local1; }
.local3 { composes: exported from 'path'; }

/* after selectors and compose */

:import('path') {
  __exported: exported;
}
:export {
  local1: __scope__local1;
  local2: __scope__local2 __scope__local1;
  local3: __scope__local3 __exported;
}
@value local2 from 'path';
.__scope__local1 {}
.__scope__local2 {}
.__scope__local3 {}

Composes plugin before selectors plugin

If exported key already exists then apply scoping and replace exported value if present in scoped list
Else add identifier as key and scoped class name as value

.local1 {}
.local2 { composes: local1; }
.local3 { composes: exported from 'path'; }

/* after composes */

:import('path') {
  __exported: exported
}
:export {
  local2: local1;
  local3: __exported;
}
.local1 {}
.local2 {}

/* after selectors */

:import('path') {
  __exported: exported
}
:export {
  local1: __scope__local1;
  local2: __scope__local2 __scope__local1;
  local3: __scope__local3 __exported;
}
.__scope__local1 {}
.__scope__local2 {}
.__scope__local3 {}

Composes plugin after selectors plugin

If exported value contains class name then append composed one
else add class name as key and composed one as value

.local1 {}
.local2 {
  composes: local1;
}
.local3 {
  composes: exported from 'path';
}

/* after selectors */

:export {
  local1: __scope__local1;
  local2: __scope__local2;
  local3: __scope__local3
}
.__scope__local1 {}
.__scope__local2 {
  composes: local1;
}
.__scope__local3 {
  composes: exported from 'path';
}

/* after composes */

:import('path') {
  __exported: exported
}
:export {
  local1: __scope__local1;
  local2: __scope__local2 __scope__local1;
  local3: __scope__local3 __exported
}
.__scope__local1 {}
.__scope__local2 {}
.__scope__local3 {}
@TrySound
Copy link
Member Author

TrySound commented Jun 6, 2017

@michael-ciniawsky @evilebottnawi
As you can see if we allow to use values with selectors order becomes important.
As work around we can introduce :external pseudo-class which will be skipped by scope plugin.
What do you think?

@alexander-akait
Copy link
Member

@TrySound good question, i wonder how other plugins do this, example cssnext, also we can migrate to mono repo and avoid this situation (as do cssnano).

@TrySound
Copy link
Member Author

TrySound commented Jun 6, 2017

As a workaround we may consider first word in exported value as alias.

@TrySound
Copy link
Member Author

TrySound commented Jun 6, 2017

Yeah. It will be semantic contract caz composes classes should be always appended.

@TrySound
Copy link
Member Author

TrySound commented Jun 6, 2017

Or we can use separate contract between these plugins via messages. This will let to provide more info.

@TrySound
Copy link
Member Author

TrySound commented Jun 6, 2017

Messages contract

postcss-icss-selectors and postcss-icss-keyframes

pass each defined identifier

{
  type: 'modules-scoped',
  name: string,
  value: string
}

postcss-icss-values matches scoped values by local keys
postcss-icss-composes matches local keys by scoped values

postcss-icss-values

passes message for each imported value (TODO: should we pass for all values?)

{
  type: 'modules-value',
  name: string,
  value: string
}

postcss-icss-selectors skips selector if values has equal value
postcss-icss-compose not warns on not existent local identifier and appends value

postcss-icss-composes

passes each composition pair

{
  type: 'modules-composed',
  name: string,
  value: string
}

postcss-icss-selectors prepends scoped identifier to matched by name local one

This contracts let's plugins rely on each other but still be optional and independent.

@TrySound TrySound reopened this Jun 25, 2017
@TrySound
Copy link
Member Author

I decide to rely on ICSS contract scheme. Values plugin will use messages to resolve original class names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants