Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@sebgroup/extract
Advanced tools
@sebgroup/extract
Extract is considered deprectaed in favor of implementing shared functionality as Web Components. See https://github.com/sebgroup/green/tree/main/libs/core
Extract is where all the business logic of Green components lives so that it can be shared between Angular and React implementations. It is called Extract since the normal way of creating a component is within Angular and React and then extracting the common logic.
Step one is always creating CSS and HTML for your component in Chlorophyll. We use Storybook to visualise the component in various states so that we can track progress and continuously check that it adheres to design guidelines. Read more in https://github.com/sebgroup/green/libs/chlorophyll
A common component consists of two parts: An interaction object and the data. Let's look at these through an example.
type Operator = '+' | '-' | '*' | '/' | '='
type Digit = number | '.'
type Press = Operator | Digit
export interface Calculator {
pressDigit: (digit: Digit) => void
pressOperator: (operator: Operator) => void
clear: () => void
}
export interface CalculatorData {
currentValue: number
numpad: Digit[][]
operators: string[]
presses: Press[]
}
These are the components we will be interacting with. The Calculator
instance
will be persistent and allows us to interact while the CalculatorData
is
changed on every interaction and allows us to render our component.
Now, lets create out Calculator.
export interface CalculatorOptions {
containerEl: HTMLElement
}
export const createCalculator = (listener: (data: CalculatorData) => void, options: CalculatorOptions): Calculator => {
// Create initial data
let data: CalculatorData = {
currentValue: 0,
numpad: [
[7, 8, 9],
[4, 5, 6],
[1, 2, 3],
[0, '.'],
],
operators: ['/', '*', '-', '+', '='],
}
// Create interaction object
const calculator: Calculator = {
clear: () => {
data = clear(data) // pure function
listener(data)
},
pressDigit: (digit) => {
data = pressDigit(data, digit) // reducer
listener(data)
},
pressOperator: (operator) => {
data = pressOperator(data, operator) // reducer
listener(data)
},
}
// Add keyboard interactions to element
// options.containerEl
// Call listener with initial data
listener(data)
}
All interactions with the calculator is done through pure functions with no side effects using a reducer pattern (basically a data structure goes in and a new, changed data structure comes out). These are easily testable. The resulting updated data model is communicated to the framewoek of choice which can then re-render making it easily bindable.
FAQs
Base library for framework components.
The npm package @sebgroup/extract receives a total of 5,890 weekly downloads. As such, @sebgroup/extract popularity was classified as popular.
We found that @sebgroup/extract demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.