@7rabbit/ink 中文文档教程
ink
精益企业架构分布
Introduction
所有的中小型公司都面临着同样的问题:代码杂乱无章,存在多种不同的命名约定、文件夹和文件约定以及实现约定。 动作以不同的方式分类并放入不同的文件和模块中,这对某些人来说很有意义,但对其他人来说却很难理解。 look and feel的实现没有太大的一致性,CSS在不同的实现中遍地开花。 总的来说,前端没有清晰和系统的方法来清理约定和实现样式,同时保持简单。
这个项目就是解决这个问题的。 它只有很少的代码行,并且是免费和公开许可的,因此可以在任何公司使用。 它所做的只是创建一个约定,将您的所有操作放在一个地方,并且操作管理状态。 正如您将了解到的,这解决了管理供应商锁定、代码的可测试性、集中知识库以及知道在哪里可以找到东西的问题。 它不是过度抽象,它只是按原样对待一切:作为行动。 所有动作都从一种状态开始,到另一种状态结束。 如果编程中有两个主要的东西,那就是对象和动作。 该项目在没有任何依赖性的情况下管理它们,因此它尽可能安全。
希望控制其代码的公司应该从这里开始。 控制应用程序中的操作。 删除使操作孤立的多余文件。 为每个操作编写测试以验证其行为。 这将有助于改进代码库。 此外,在这里保存您的操作对象。 将配置和设置以及任意数据保存在一个地方以简化调试。 使复杂的操作变得简单。 帮助新手轻松掌握代码,这样他们就不必通过复杂的导入和文件网络进行筛选。 这将使每个人都更容易理解代码,并提高产品开发的速度。
Installation
npm install @7rabbit/ink
Illustration
Ink 是一个美化的“商店”。 所有商店都是“状态”,它们都是同一件事。 我们进一步采取了一种“事物”类型的“状态”,并创建了两种类型的事物来简化开发:操作和对象。 JavaScript 中的动作只是一个函数。 函数接受输入并可选地返回输出或以其他方式产生效果(或什么都不做)。 一个对象是一段数据,它本身可以是一个函数,或者更好的是一个对象、一组位,或者一个数组、字符串、数字、正则表达式等。
这是一个 Hello World 示例。
import Ink from '@7rabbit/ink'
let ink = new Ink()
ink.attachModule(attachLogger)
ink.invokeAction('log', 'hello world')
ink.detachModule(attachLogger)
ink.invokeAction('log', 'hello world')
function attachLogger(ink) {
ink.attachAction('log', log)
return detachModule
function detachModule() {
ink.detachAction('log')
}
function log(x) {
console.log(x)
}
}
下面的其余部分是一个 API 参考,记录了 ink
对象上的每个方法。
commitObject(name, object)
通过键 name
存储一个 object
。
attachObject(name, object)
如果已经有一个通过键name
存储的对象,那么它会抛出一个错误,否则它通过键name
存储object
。
selectObject(name)
返回具有键 name
的对象。
expectObject(name)
如果不存在键 name
存储的对象,则抛出错误,否则返回键 name
的对象。
detachObject(name)
从存储中删除键 name
下的对象。
commitAction(name, action)
通过键 name
存储一个 action
。
attachAction(name, action)
如果已经有一个由键 name
存储的动作,那么它会抛出一个错误,否则它会通过键 name
存储 action
。
selectAction(name)
返回带有键 name
的操作。
expectAction(name)
如果键 name
没有存储操作,则抛出错误,否则返回键 name
的操作。
detachAction(name)
从商店中删除键 name
下的操作。
invokeAction(name, ...args)
使用 args
调用键 name
下的操作。
attachModule(module)
将函数 module
应用于商店。
detachModule(module)
取消将函数 module
应用到商店。
ink
Lean Enterprise Architecture Distribution
Introduction • Installation • Illustration
Introduction
All small and medium sized companies suffer the same problem: code is a mess and disorganized, there are multiple different naming conventions, folder and file conventions, and implementation conventions. Actions are classified in different ways and placed into different files and modules, which makes sense to some and is difficult to understand for others. There is not much consistency in the implementation of the look and feel, and CSS is all over the place in different implementations. Overall, there is no clear and systematic approach to the frontend that cleans up the conventions and implementation styles and at the same times keeps it simple.
This project is a solution to this problem. It is very few lines of code and is freely and openly licensed so it can be used at any company. All it does is create a convention to place all of your actions in one place, and actions manage state. As you will learn this solves the problem of managing vendor lockin, of testability of the code, of centralizing the knowledge base and of knowing where to find things. It is not an over-abstraction, it just treats everything as they are: as actions. All actions start at one state and end at another. If there are two main things in programming they are objects and actions. This project manages them both without any dependencies, so it is as secure as it can be.
Companies looking to take control of their code should start here. Gain control over the actions in the application. Shed the excess files that kept the actions siloed. Write tests for each action to verify its behavior. This will help improve the codebase. In addition, save the objects of your actions here. Keep configuration and settings and arbitrary data in one place to ease debuggability. To make it simple to stub out a complicated action. To help ease newcomers into the code, so they don't have to weed through a complicated network of imports and files. This will make the code easier to understand for everyone, and will increase the velocity at which product is developed.
Installation
npm install @7rabbit/ink
Illustration
Ink is a glorified "store". All a store is is "state", they both mean the same thing. We have taken one step further to take that "state" of one type of "thing" and created two types of things to simplify development: actions and objects. An action in JavaScript is simply a function. A function takes input and optionally returns output or otherwise causes an effect (or does nothing). An object is a piece of data, whether itself a function, or better, an object, set of bits, or an array, string, number, regex, etc.
This is a Hello World example.
import Ink from '@7rabbit/ink'
let ink = new Ink()
ink.attachModule(attachLogger)
ink.invokeAction('log', 'hello world')
ink.detachModule(attachLogger)
ink.invokeAction('log', 'hello world')
function attachLogger(ink) {
ink.attachAction('log', log)
return detachModule
function detachModule() {
ink.detachAction('log')
}
function log(x) {
console.log(x)
}
}
The rest of what follows is an API reference documenting every method on the ink
object.
commitObject(name, object)
Stores an object
by the key name
.
attachObject(name, object)
If there already is an object stored by key name
, then it throws an error, otherwise it stores object
by the key name
.
selectObject(name)
Returns the object with the key name
.
expectObject(name)
If there is not an object stored by key name
, then it throws an error, otherwise it returns the object with the key name
.
detachObject(name)
Removes the object under the key name
from the store.
commitAction(name, action)
Stores an action
by the key name
.
attachAction(name, action)
If there already is an action stored by key name
, then it throws an error, otherwise it stores action
by the key name
.
selectAction(name)
Returns the action with the key name
.
expectAction(name)
If there is not an action stored by key name
, then it throws an error, otherwise it returns the action with the key name
.
detachAction(name)
Removes the action under the key name
from the store.
invokeAction(name, ...args)
Calls the action under the key name
with args
.
attachModule(module)
Applies the function module
to the store.
detachModule(module)
Unapplies the function module
to the store.
你可能也喜欢
- 3d-react-carousal 中文文档教程
- 720zforever-utils 中文文档教程
- @0x0006e/babel-preset-react 中文文档教程
- @1hive/default-token-list 中文文档教程
- @36node-fcp/ecs-api-sdk-js 中文文档教程
- @3dorchard/generator-typescript-boilerplate 中文文档教程
- @47deg/robeen 中文文档教程
- @4a/packing 中文文档教程
- @4qwerty7/sim-node 中文文档教程
- @a11ywatch/website-source-builder 中文文档教程