Skip to content
Permalink
Browse files

feat: use parcel instead of webpack, integrate with CI and ESLint (#20)

  • Loading branch information
JounQin committed Aug 14, 2019
1 parent 035520f commit aedba0b617e615a40e770483253867ad31941ea7
Showing with 6,161 additions and 9,152 deletions.
  1. +7 −0 . huskyrc
  2. +3 −0 .commitrc
  3. +10 −0 .editorconfig
  4. +5 −0 .eslintignore
  5. +20 −0 .eslintrc.js
  6. +6 −9 .gitignore
  7. +4 −0 .lint-stagedrc
  8. +4 −0 .prettierrc
  9. +45 −0 .travis.yml
  10. +14 −3 README.md
  11. +17 −0 codechecks.yml
  12. +2 −3 example/index.html
  13. +15 −13 example/index.tsx
  14. +3 −3 example/src/components/Counter/index.tsx
  15. +3 −2 example/src/components/Todo/index.tsx
  16. +5 −4 example/src/models/CounterModel.ts
  17. +6 −9 example/src/models/TodoModel.ts
  18. +3 −3 example/src/services/TodoService.ts
  19. +1 −5 example/tsconfig.json
  20. +0 −7,275 example/yarn.lock
  21. +3 −0 jest.config.js
  22. +37 −36 package.json
  23. +1 −1 renovate.json
  24. +2 −1 src/context/StatedBeanConsumer.tsx
  25. +2 −1 src/context/StatedBeanContext.ts
  26. +4 −3 src/context/StatedBeanProvider.tsx
  27. +8 −3 src/core/EffectContext.ts
  28. +20 −17 src/core/StatedBeanApplication.ts
  29. +11 −7 src/core/StatedBeanContainer.ts
  30. +3 −3 src/core/StatedBeanFactory.ts
  31. +2 −2 src/decorator/PostProvided.ts
  32. +2 −2 src/decorator/StatedBean.ts
  33. +3 −0 src/event/Event.ts
  34. +11 −11 src/hooks/useContainer.ts
  35. +7 −7 src/hooks/useStatedBean.ts
  36. +1 −1 src/interceptor/StatedInterceptor.ts
  37. +2 −2 src/metadata/index.ts
  38. +9 −7 src/metadata/storage.ts
  39. +6 −0 src/tsconfig.cjs.json
  40. +10 −0 src/tsconfig.es.json
  41. +1 −3 src/types/ClassType.ts
  42. +7 −7 test/metadata.test.ts
  43. +17 −15 test/provider.test.tsx
  44. +0 −10 tsconfig.es.json
  45. +17 −18 tsconfig.json
  46. +0 −9 tsconfig.lib.json
  47. +0 −42 webpack.config.js
  48. +5,802 −1,615 yarn.lock
@@ -0,0 +1,7 @@
{
"$schema": "https://schemastore.azurewebsites.net/schemas/json/huskyrc.json",
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@@ -0,0 +1,5 @@
.cache
coverage
dist
node_modules
output
@@ -0,0 +1,20 @@
const { overrides } = require('eslint-config-1stg/overrides');

module.exports = {
extends: '1stg',
overrides: [
...overrides,
{
files: '*.{ts,tsx}',
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/member-naming': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-type-alias': 0,
'standard/no-callback-literal': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/restrict-plus-operands': 0,
},
},
],
};
@@ -1,12 +1,9 @@
*.log
.DS_Store
node_modules
*.tsbuildinfo
.cache
.rts2_cache_cjs
.rts2_cache_esm
.rts2_cache_umd
dist

coverage
# local history
.DS_Store
.history
coverage
dist
node_modules
output
@@ -0,0 +1,4 @@
{
"*.{json,md,yml}": ["prettier --write", "git add"],
"*.{js,ts,tsx}": ["eslint --fix", "git add"]
}
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
@@ -0,0 +1,45 @@
language: node_js

node_js: --lts

cache: yarn

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH="$HOME/.yarn/bin:$PATH"
- git config --global user.name 'JounQin'
- git config --global user.email 'admin@1stg.me'

install: yarn --frozen-lockfile

before_script:
- export TRAVIS_REPO_OWNER=${TRAVIS_REPO_SLUG%/*}
- export TRAVIS_REPO_NAME=${TRAVIS_REPO_SLUG#*/}

script:
- yarn lint
- yarn test
- yarn build:cjs
- yarn build:es
- yarn build:example --public-url /$TRAVIS_REPO_NAME/

after_success:
- yarn global add codecov
- codecov

deploy:
provider: pages
email: admin@1stg.me
name: JounQin
skip_cleanup: true
github_token: $GH_TOKEN
keep_history: true
allow_empty_commit: false
local_dir: dist
on:
branch: master

after_script:
- yarn add -D @codechecks/client @codechecks/build-size-watcher @codechecks/commit-deployment @codechecks/type-coverage-watcher -W
- yarn build
- yarn codechecks
@@ -1,7 +1,18 @@
# stated-bean

[![npm version](https://badge.fury.io/js/stated-bean.svg)](https://badge.fury.io/js/stated-bean)

[![Travis](https://img.shields.io/travis/com/mjolnirjs/stated-bean.svg)](https://travis-ci.com/mjolnirjs/stated-bean)
[![Codecov](https://img.shields.io/codecov/c/gh/mjolnirjs/stated-bean)](https://codecov.io/gh/mjolnirjs/stated-bean)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fmjolnirjs%2Fstated-bean%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![npm](https://img.shields.io/npm/v/stated-bean.svg)](https://www.npmjs.com/package/stated-bean)
[![GitHub release](https://img.shields.io/github/release/mjolnirjs/stated-bean)](https://github.com/mjolnirjs/stated-bean/releases)

[![David Peer](https://img.shields.io/david/peer/mjolnirjs/stated-bean.svg)](https://david-dm.org/mjolnirjs/stated-bean?type=peer)
[![David](https://img.shields.io/david/mjolnirjs/stated-bean.svg)](https://david-dm.org/mjolnirjs/stated-bean)
[![David Dev](https://img.shields.io/david/dev/mjolnirjs/stated-bean.svg)](https://david-dm.org/mjolnirjs/stated-bean?type=dev)

[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![codechecks.io](https://raw.githubusercontent.com/codechecks/docs/master/images/badges/badge-default.svg?sanitize=true)](https://codechecks.io)
## Introduction

stated-bean is a lite & scalable state management library with react hooks. Inspired by [unstated-next](https://github.com/jamiebuilds/unstated-next)
@@ -51,7 +62,7 @@ import { StatedBean, Stated } from 'stated-bean';
@StatedBean()
export class Counter {
@Stated()
public count: number = 0;
count: number = 0;
increment = () => {
this.count++;
@@ -0,0 +1,17 @@
checks:
- name: build-size-watcher
options:
files:
- path: dist/**/*.*
- name: commit-deployment
options:
buildPath: ./output
- name: type-coverage-watcher
options:
ignoreCatch: true
ignoreFiles:
- .cache
- coverage
- dist
- output
strict: true
@@ -1,14 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Playground</title>
</head>

<body>
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="../stated-bean-example.js"></script>
<script src="./index.tsx"></script>
</body>
</html>
@@ -1,38 +1,41 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import { Container } from 'inversify';
import 'reflect-metadata';
import '@abraham/reflection';
import { ReflectiveInjector } from 'injection-js';

import {
StatedBeanProvider,
ClassType,
StatedBeanApplication,
IBeanFactory,
EffectContext,
StatedInterceptor,
NextCaller,
} from '../src';

import { CounterModel } from './src/models/CounterModel';
import { Counter } from './src/components/Counter';
import { TodoApp } from './src/components/Todo';
import { TodoModel } from './src/models/TodoModel';
import { TodoService } from './src/services/TodoService';

import ReactDOM from 'react-dom';
import React from 'react';

const container = new Container({ autoBindInjectable: true });
const app = new StatedBeanApplication();

const inversifyBeanFactory = {
get: (type: ClassType) => {
return container.get(type);
const rootInjector = ReflectiveInjector.resolveAndCreate([TodoService]);

const inversifyBeanFactory: IBeanFactory = {
get(type) {
return ReflectiveInjector.resolveAndCreate([type], rootInjector).get(type);
},
} as IBeanFactory;
};

class LoggerInterceptor implements StatedInterceptor {
async stateInitIntercept(context: EffectContext, next: NextCaller) {
console.log('1. before init', context.toString());
await next();
console.log('1. after init', context.toString());
}

async stateChangeIntercept(context: EffectContext, next: NextCaller) {
console.log('1. before change', context.toString());
await next();
@@ -46,6 +49,7 @@ class LoggerInterceptor2 implements StatedInterceptor {
await next();
console.log('2. after init', context.toString());
}

async stateChangeIntercept(context: EffectContext, next: NextCaller) {
console.log('2. before change', context.toString());
await next();
@@ -66,6 +70,4 @@ const App = () => {
);
};

console.log('1111');

ReactDOM.render(<App />, document.getElementById('root'));
@@ -1,8 +1,8 @@
import * as React from 'react';

import { useStatedBean } from '../../../../src';
import { CounterModel } from '../../models/CounterModel';

import { useStatedBean } from 'stated-bean';
import React from 'react';

export function Counter() {
const counter = useStatedBean(CounterModel);

@@ -1,7 +1,8 @@
import * as React from 'react';
import { useStatedBean } from '../../../../src';
import { TodoModel, Todo } from '../../models/TodoModel';

import { useStatedBean } from 'stated-bean';
import React from 'react';

function TodoList(props: { items: Todo[] }) {
return (
<ul>
@@ -1,11 +1,12 @@
import { StatedBean, Stated } from '../../../src';
import { injectable } from 'inversify';
import { Injectable } from 'injection-js';

import { StatedBean, Stated } from 'stated-bean';

@injectable()
@StatedBean()
@Injectable()
export class CounterModel {
@Stated()
public count: number = 0;
count = 0;

increment = () => {
this.count++;
@@ -1,4 +1,5 @@
import { injectable, inject } from 'inversify';
import { Injectable, Inject } from 'injection-js';

import { StatedBean, Stated, PostProvided } from '../../../src';
import { TodoService } from '../services/TodoService';

@@ -8,20 +9,16 @@ export interface Todo {
state: 'todo' | 'done';
}

@injectable()
@StatedBean()
@Injectable()
export class TodoModel {
@Stated()
public todoList: Todo[] = [];
todoList: Todo[] = [];

@Stated()
public current: Todo = {} as Todo;

private todoService: TodoService;
current: Todo = {} as Todo;

public constructor(@inject(TodoService) todoService: TodoService) {
this.todoService = todoService;
}
constructor(@Inject(TodoService) private readonly todoService: TodoService) {}

@PostProvided()
async fetchTodo() {
@@ -1,8 +1,8 @@
import { injectable } from 'inversify';
import { Injectable } from 'injection-js';

@injectable()
@Injectable()
export class TodoService {
public async fetchTodoList() {
async fetchTodoList() {
return new Promise(resolve => {
setTimeout(() => {
resolve([
@@ -1,10 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"experimentalDecorators": true,
"baseUrl": "../",
"paths": {
"stated-bean": ["../src"]
}
"module": "esnext"
}
}

0 comments on commit aedba0b

Please sign in to comment.
You can’t perform that action at this time.