react-obsidian 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/dist/src/Obsidian.d.ts +2 -2
  2. package/dist/src/Obsidian.d.ts.map +1 -1
  3. package/dist/src/Obsidian.js.map +1 -1
  4. package/dist/src/graph/registry/GraphRegistry.d.ts +1 -0
  5. package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -1
  6. package/dist/src/graph/registry/GraphRegistry.js +8 -1
  7. package/dist/src/graph/registry/GraphRegistry.js.map +1 -1
  8. package/dist/src/graph/registry/NullProps.d.ts +4 -0
  9. package/dist/src/graph/registry/NullProps.d.ts.map +1 -0
  10. package/dist/src/graph/registry/NullProps.js +25 -0
  11. package/dist/src/graph/registry/NullProps.js.map +1 -0
  12. package/dist/src/index.d.ts +1 -0
  13. package/dist/src/index.d.ts.map +1 -1
  14. package/dist/src/index.js +4 -1
  15. package/dist/src/index.js.map +1 -1
  16. package/dist/src/utils/isDev.d.ts +2 -0
  17. package/dist/src/utils/isDev.d.ts.map +1 -0
  18. package/dist/src/utils/isDev.js +17 -0
  19. package/dist/src/utils/isDev.js.map +1 -0
  20. package/dist/test/fixtures/LifecycleBoundGraph.d.ts +3 -2
  21. package/dist/test/fixtures/LifecycleBoundGraph.d.ts.map +1 -1
  22. package/dist/test/fixtures/LifecycleBoundGraph.js +9 -0
  23. package/dist/test/fixtures/LifecycleBoundGraph.js.map +1 -1
  24. package/dist/testkit/index.d.ts +6 -1
  25. package/dist/testkit/index.d.ts.map +1 -1
  26. package/dist/testkit/index.js +11 -17
  27. package/dist/testkit/index.js.map +1 -1
  28. package/dist/testkit/mockGraphs.d.ts +4 -0
  29. package/dist/testkit/mockGraphs.d.ts.map +1 -0
  30. package/dist/testkit/mockGraphs.js +23 -0
  31. package/dist/testkit/mockGraphs.js.map +1 -0
  32. package/dist/testkit/mockModel.d.ts +3 -0
  33. package/dist/testkit/mockModel.d.ts.map +1 -0
  34. package/dist/testkit/mockModel.js +14 -0
  35. package/dist/testkit/mockModel.js.map +1 -0
  36. package/package.json +1 -1
  37. package/src/Obsidian.ts +3 -3
  38. package/src/graph/registry/GraphRegistry.ts +9 -1
  39. package/src/graph/registry/NullProps.ts +23 -0
  40. package/src/index.ts +1 -0
  41. package/src/utils/isDev.ts +12 -0
  42. package/testkit/index.ts +11 -14
  43. package/testkit/mockGraphs.ts +20 -0
  44. package/testkit/mockModel.ts +10 -0
  45. package/.buildkite/pipeline.yml +0 -10
  46. package/.eslintignore +0 -1
  47. package/.eslintrc.json +0 -104
  48. package/.vscode/settings.json +0 -5
  49. package/babel.config.js +0 -13
  50. package/documentation/README.md +0 -41
  51. package/documentation/babel.config.js +0 -3
  52. package/documentation/blog/2019-05-28-first-blog-post.md +0 -12
  53. package/documentation/blog/2019-05-29-long-blog-post.md +0 -44
  54. package/documentation/blog/2021-08-01-mdx-blog-post.mdx +0 -20
  55. package/documentation/blog/2021-08-26-welcome/docusaurus-plushie-banner.jpeg +0 -0
  56. package/documentation/blog/2021-08-26-welcome/index.md +0 -25
  57. package/documentation/blog/authors.yml +0 -17
  58. package/documentation/docs/documentation/documentation.mdx +0 -190
  59. package/documentation/docs/documentation/installation.mdx +0 -56
  60. package/documentation/docs/documentation/meta/clearingGraphs.mdx +0 -13
  61. package/documentation/docs/documentation/meta/middlewares.mdx +0 -27
  62. package/documentation/docs/documentation/usage/ClassComponents.mdx +0 -18
  63. package/documentation/docs/documentation/usage/Classes.mdx +0 -41
  64. package/documentation/docs/documentation/usage/FunctionalComponents.mdx +0 -57
  65. package/documentation/docs/documentation/usage/Graphs.mdx +0 -154
  66. package/documentation/docs/documentation/usage/Hooks.mdx +0 -85
  67. package/documentation/docs/documentation/usage/Reactivity.mdx +0 -116
  68. package/documentation/docs/documentation/usage/ServiceLocator.mdx +0 -38
  69. package/documentation/docs/documentation/usage/_category_.json +0 -9
  70. package/documentation/docs/guides/configurableApplications.mdx +0 -205
  71. package/documentation/docs/guides/mockDependencies.mdx +0 -141
  72. package/documentation/docusaurus.config.js +0 -151
  73. package/documentation/package-lock.json +0 -22975
  74. package/documentation/package.json +0 -47
  75. package/documentation/sidebars.js +0 -34
  76. package/documentation/src/components/HomepageFeatures/index.tsx +0 -71
  77. package/documentation/src/components/HomepageFeatures/styles.module.css +0 -11
  78. package/documentation/src/css/custom.css +0 -30
  79. package/documentation/src/pages/index.module.css +0 -23
  80. package/documentation/src/pages/index.tsx +0 -41
  81. package/documentation/src/pages/playground/index.mdx +0 -21
  82. package/documentation/src/theme/SearchBar.js +0 -19
  83. package/documentation/static/.nojekyll +0 -0
  84. package/documentation/static/img/api.svg +0 -101
  85. package/documentation/static/img/favicon.ico +0 -0
  86. package/documentation/static/img/logo.svg +0 -265
  87. package/documentation/static/img/obsidian.png +0 -0
  88. package/documentation/static/img/prototype.svg +0 -1
  89. package/documentation/static/img/stethoscope.svg +0 -37
  90. package/documentation/tsconfig.json +0 -7
  91. package/documentation/yarn.lock +0 -8167
  92. package/example/.buckconfig +0 -6
  93. package/example/.editorconfig +0 -3
  94. package/example/.eslintrc.js +0 -4
  95. package/example/.flowconfig +0 -65
  96. package/example/.gitattributes +0 -3
  97. package/example/.prettierrc.js +0 -7
  98. package/example/.watchmanconfig +0 -1
  99. package/example/App.tsx +0 -31
  100. package/example/MyInjectedComponent.tsx +0 -37
  101. package/example/__tests__/App-test.js +0 -14
  102. package/example/android/app/BUCK +0 -55
  103. package/example/android/app/build.gradle +0 -227
  104. package/example/android/app/build_defs.bzl +0 -19
  105. package/example/android/app/debug.keystore +0 -0
  106. package/example/android/app/proguard-rules.pro +0 -10
  107. package/example/android/app/src/debug/AndroidManifest.xml +0 -13
  108. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +0 -72
  109. package/example/android/app/src/main/AndroidManifest.xml +0 -25
  110. package/example/android/app/src/main/java/com/example/MainActivity.java +0 -15
  111. package/example/android/app/src/main/java/com/example/MainApplication.java +0 -80
  112. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  113. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  114. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  115. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  116. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  117. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  118. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  119. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  120. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  121. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  122. package/example/android/app/src/main/res/values/strings.xml +0 -3
  123. package/example/android/app/src/main/res/values/styles.xml +0 -8
  124. package/example/android/build.gradle +0 -38
  125. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  126. package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  127. package/example/android/gradle.properties +0 -28
  128. package/example/android/gradlew +0 -185
  129. package/example/android/gradlew.bat +0 -89
  130. package/example/android/settings.gradle +0 -3
  131. package/example/app.json +0 -4
  132. package/example/babel.config.js +0 -8
  133. package/example/index.js +0 -9
  134. package/example/ios/Podfile +0 -30
  135. package/example/ios/Podfile.lock +0 -526
  136. package/example/ios/example/AppDelegate.h +0 -8
  137. package/example/ios/example/AppDelegate.m +0 -62
  138. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
  139. package/example/ios/example/Images.xcassets/Contents.json +0 -6
  140. package/example/ios/example/Info.plist +0 -55
  141. package/example/ios/example/LaunchScreen.storyboard +0 -47
  142. package/example/ios/example/main.m +0 -9
  143. package/example/ios/example.xcodeproj/project.pbxproj +0 -689
  144. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +0 -88
  145. package/example/ios/example.xcworkspace/contents.xcworkspacedata +0 -10
  146. package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  147. package/example/ios/exampleTests/Info.plist +0 -24
  148. package/example/ios/exampleTests/exampleTests.m +0 -65
  149. package/example/metro.config.js +0 -44
  150. package/example/package.json +0 -35
  151. package/example/tsconfig.json +0 -42
  152. package/global.d.ts +0 -1
  153. package/jest.config.js +0 -17
  154. package/jest.setup-after-env.js +0 -4
  155. package/tsconfig.base.json +0 -42
  156. package/tsconfig.json +0 -3
  157. package/tsconfig.prod.json +0 -7
package/.eslintrc.json DELETED
@@ -1,104 +0,0 @@
1
- {
2
- "root": true,
3
- "env": {
4
- "es2021": true,
5
- "jest": true
6
- },
7
- "ignorePatterns": ["**/*.config.js"],
8
- "extends": [
9
- "airbnb-base",
10
- "airbnb-typescript",
11
- "plugin:react/recommended",
12
- "plugin:@typescript-eslint/recommended",
13
- "plugin:import/typescript"
14
- ],
15
- "parser": "@typescript-eslint/parser",
16
- "parserOptions": {
17
- "project": "./tsconfig.json",
18
- "ecmaVersion": 2021,
19
- "sourceType": "module",
20
- "ecmaFeatures": {
21
- "jsx": true
22
- }
23
- },
24
- "plugins": [
25
- "react",
26
- "@typescript-eslint",
27
- "import-newlines",
28
- "unused-imports"
29
- ],
30
- "rules": {
31
- "max-len": ["error", {"code": 115}],
32
- "lines-between-class-members": ["error", "always", {"exceptAfterSingleLine": true}],
33
- "import/extensions": "off",
34
- "@typescript-eslint/no-non-null-assertion": "off",
35
- "no-useless-constructor": "off",
36
- "@typescript-eslint/member-delimiter-style": "error",
37
- "import/no-unresolved": "off",
38
- "class-methods-use-this": "off",
39
- "react/jsx-filename-extension": ["error", {"extensions": [".js", ".ts", ".jsx", ".tsx"]}],
40
- "react/jsx-props-no-spreading": "off",
41
- "no-use-before-define": "off",
42
- "@typescript-eslint/no-use-before-define": ["off"],
43
- "no-restricted-syntax": "off",
44
- "import/no-named-as-default": "off",
45
- "@typescript-eslint/ban-types": ["off"],
46
- "import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
47
- "max-classes-per-file": ["off"],
48
- "curly": ["error", "multi-line"],
49
- "semi": ["error", "always"],
50
- "comma-dangle": ["error", "always-multiline"],
51
- "function-call-argument-newline": ["error", "consistent"],
52
- "function-paren-newline": ["error", "multiline-arguments"],
53
- "object-curly-newline": [
54
- "error",
55
- {
56
- "ObjectExpression": {
57
- "multiline": true,
58
- "consistent": true
59
- },
60
- "ObjectPattern": {
61
- "multiline": true,
62
- "consistent": true
63
- }
64
- }
65
- ],
66
- "no-whitespace-before-property": "error",
67
- "import-newlines/enforce": [
68
- "error",
69
- {
70
- "items": 3,
71
- "max-len": 115,
72
- "semi": false
73
- }
74
- ],
75
- "react/display-name": "off",
76
- "no-plusplus": "off",
77
- "no-trailing-spaces": "error",
78
- "no-shadow": "off",
79
- "@typescript-eslint/no-shadow": ["error", {"allow": ["Graph"]}],
80
- "react/button-has-type": "off",
81
- "react/jsx-one-expression-per-line": ["off"],
82
- "arrow-body-style": ["off"],
83
- "@typescript-eslint/quotes": ["error", "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
84
- "@typescript-eslint/lines-between-class-members": "off",
85
- "@typescript-eslint/no-explicit-any": "off",
86
- "import/prefer-default-export": "off",
87
- "@typescript-eslint/no-unused-vars": "off",
88
- "unused-imports/no-unused-imports": "error",
89
- "unused-imports/no-unused-vars": [
90
- "error",
91
- { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
92
- ]
93
- },
94
- "settings": {
95
- "import/resolver": {
96
- "node": {
97
- "extensions": [".js", ".jsx", ".ts", ".tsx"]
98
- }
99
- },
100
- "react": {
101
- "version": "detect"
102
- }
103
- }
104
- }
@@ -1,5 +0,0 @@
1
- {
2
- "cSpell.words": [
3
- "unmagler"
4
- ]
5
- }
package/babel.config.js DELETED
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- ['@babel/preset-env', { targets: { node: 'current' }}],
4
- ['@babel/preset-typescript', {'onlyRemoveTypeImports': true}],
5
- '@babel/preset-react',
6
- ],
7
- plugins: [
8
- `${__dirname}/dist/transformers/babel-plugin-obsidian`,
9
- ['@babel/plugin-proposal-decorators', { legacy: true }],
10
- '@babel/plugin-transform-class-properties',
11
- 'babel-plugin-parameter-decorator'
12
- ],
13
- };
@@ -1,41 +0,0 @@
1
- # Website
2
-
3
- This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
4
-
5
- ### Installation
6
-
7
- ```
8
- $ yarn
9
- ```
10
-
11
- ### Local Development
12
-
13
- ```
14
- $ yarn start
15
- ```
16
-
17
- This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18
-
19
- ### Build
20
-
21
- ```
22
- $ yarn build
23
- ```
24
-
25
- This command generates static content into the `build` directory and can be served using any static contents hosting service.
26
-
27
- ### Deployment
28
-
29
- Using SSH:
30
-
31
- ```
32
- $ USE_SSH=true yarn deploy
33
- ```
34
-
35
- Not using SSH:
36
-
37
- ```
38
- $ GIT_USER=<Your GitHub username> yarn deploy
39
- ```
40
-
41
- If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3
- };
@@ -1,12 +0,0 @@
1
- ---
2
- slug: first-blog-post
3
- title: First Blog Post
4
- authors:
5
- name: Gao Wei
6
- title: Docusaurus Core Team
7
- url: https://github.com/wgao19
8
- image_url: https://github.com/wgao19.png
9
- tags: [hola, docusaurus]
10
- ---
11
-
12
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
@@ -1,44 +0,0 @@
1
- ---
2
- slug: long-blog-post
3
- title: Long Blog Post
4
- authors: endi
5
- tags: [hello, docusaurus]
6
- ---
7
-
8
- This is the summary of a very long blog post,
9
-
10
- Use a `<!--` `truncate` `-->` comment to limit blog post size in the list view.
11
-
12
- <!--truncate-->
13
-
14
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
15
-
16
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
17
-
18
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
19
-
20
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
21
-
22
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
23
-
24
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
25
-
26
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
27
-
28
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
29
-
30
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
31
-
32
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
33
-
34
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
35
-
36
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
37
-
38
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
39
-
40
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
41
-
42
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
43
-
44
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
@@ -1,20 +0,0 @@
1
- ---
2
- slug: mdx-blog-post
3
- title: MDX Blog Post
4
- authors: [slorber]
5
- tags: [docusaurus]
6
- ---
7
-
8
- Blog posts support [Docusaurus Markdown features](https://docusaurus.io/docs/markdown-features), such as [MDX](https://mdxjs.com/).
9
-
10
- :::tip
11
-
12
- Use the power of React to create interactive blog posts.
13
-
14
- ```js
15
- <button onClick={() => alert('button clicked!')}>Click me!</button>
16
- ```
17
-
18
- <button onClick={() => alert('button clicked!')}>Click me!</button>
19
-
20
- :::
@@ -1,25 +0,0 @@
1
- ---
2
- slug: welcome
3
- title: Welcome
4
- authors: [slorber, yangshun]
5
- tags: [facebook, hello, docusaurus]
6
- ---
7
-
8
- [Docusaurus blogging features](https://docusaurus.io/docs/blog) are powered by the [blog plugin](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog).
9
-
10
- Simply add Markdown files (or folders) to the `blog` directory.
11
-
12
- Regular blog authors can be added to `authors.yml`.
13
-
14
- The blog post date can be extracted from filenames, such as:
15
-
16
- - `2019-05-30-welcome.md`
17
- - `2019-05-30-welcome/index.md`
18
-
19
- A blog post folder can be convenient to co-locate blog post images:
20
-
21
- ![Docusaurus Plushie](./docusaurus-plushie-banner.jpeg)
22
-
23
- The blog supports tags as well!
24
-
25
- **And if you don't want a blog**: just delete this directory, and use `blog: false` in your Docusaurus config.
@@ -1,17 +0,0 @@
1
- endi:
2
- name: Endilie Yacop Sucipto
3
- title: Maintainer of Docusaurus
4
- url: https://github.com/endiliey
5
- image_url: https://github.com/endiliey.png
6
-
7
- yangshun:
8
- name: Yangshun Tay
9
- title: Front End Engineer @ Facebook
10
- url: https://github.com/yangshun
11
- image_url: https://github.com/yangshun.png
12
-
13
- slorber:
14
- name: Sébastien Lorber
15
- title: Docusaurus maintainer
16
- url: https://sebastienlorber.com
17
- image_url: https://github.com/slorber.png
@@ -1,190 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- import Tabs from '@theme/Tabs';
6
- import TabItem from '@theme/TabItem';
7
-
8
-
9
- # Introduction
10
-
11
- Obsidian is a dependency injection container with first-class support for React and React Native applications.
12
-
13
- Get started by **following the installation guide** bellow. Or **try Obsidian immediately** in the **[Online Playground](/playground)**.
14
-
15
- ## The 2 steps tutorial for injecting dependencies with Obsidian
16
-
17
- ### Step 1: Declare how dependencies should be created
18
-
19
- Define a singleton graph that is instantiated once and is retained throughout the lifespan of the application. All dependencies it provides are also singletons. The graph bellow provides two dependencies that can be injected: `fooService` and `barManager`.
20
- ```ts title="A singleton graph that provides two dependencies"
21
- import {Singleton, Graph, ObjectGraph, Provides} from 'react-obsidian';
22
-
23
-
24
- @Singleton() @Graph()
25
- export class ApplicationGraph extends ObjectGraph {
26
-
27
- // fooService requires a barManager so it receives one as a parameter.
28
- @Provides()
29
- fooService(barManager: BarManager): FooService {
30
- return new FooService(barManager);
31
- }
32
-
33
-
34
- @Provides()
35
- barManager(): BarManager {
36
- return new BarManager();
37
- }
38
- }
39
- ```
40
-
41
- ### Step 2: Inject the dependencies
42
- Obsidian can inject dependencies into components, hooks, and classes.
43
-
44
-
45
-
46
- <Tabs>
47
- <TabItem value="functionalComponent" label="Functional component injection" default>
48
-
49
- Injecting React functional components essentially revolves around two things: declaring the required dependencies in the components's props and exporting an injected component using the `injectComponent` function.
50
-
51
- ```ts title="MyComponent.tsx"
52
- import {DependenciesOf, injectComponent} from 'react-obsidian';
53
- import {ApplicationGraph} from './ApplicationGraph';
54
-
55
- // 1. Declare which dependencies should be injected.
56
- type Props = DependenciesOf<ApplicationGraph, 'fooService'>; // {fooService: FooService}
57
-
58
- // 2. Implement the component.
59
- const myComponent = ({fooService}: Props) => {
60
- // Do something useful with fooService
61
- }
62
-
63
- // 3. Export the injected component.
64
- export default injectComponent(myComponent, ApplicationGraph);
65
- ```
66
-
67
- Now we can use the injected component without providing its dependencies manually:
68
- ```tsx title="SomeComponent.tsx"
69
- import MyComponent from './MyComponent';
70
-
71
- const SomeComponent = () => {
72
- // 4. Render the component - its dependencies are resolved automatically by Obsidian.
73
- return <MyComponent />;
74
- }
75
- ```
76
- </TabItem>
77
- <TabItem value="hook" label="Hook injection">
78
-
79
- Hooks are injected in a similar way to functional components. The only difference is that the `injectHook` function is used instead of `injectComponent`.
80
-
81
- ```ts title="MyHook.ts"
82
- import {DependenciesOf, injectHook} from 'react-obsidian';
83
- import {ApplicationGraph} from './ApplicationGraph';
84
-
85
- // 1. Declare which dependencies should be injected.
86
- type Props = DependenciesOf<ApplicationGraph, 'fooService'>; // {fooService: FooService}
87
-
88
- // 2. Implement the hook.
89
- const myHook = ({fooService}: Props) => {
90
- // Do something useful with fooService
91
- }
92
-
93
- // 3. Export the injected hook.
94
- export default injectHook(myHook, ApplicationGraph);
95
- ```
96
-
97
- The injected hook can be used without providing its dependencies manually:
98
- ```tsx title="SomeComponent.tsx"
99
- import myHook from './MyHook';
100
-
101
- const SomeComponent = () => {
102
- // 4. Use the hook without providing any dependencies manually - they are injected automatically.
103
- myHook();
104
-
105
- return <>Obsidian is awesome!</>;
106
- }
107
- ```
108
- </TabItem>
109
- <TabItem value="classComponent" label="Class component injection">
110
-
111
- To inject a class, annotate it with the `@Injectable` decorator. The `@Injectable` decorator takes a single parameter - the graph that should be used to resolve the dependencies. Declare the dependencies as class members and annotate them with the `@Inject` decorator.
112
-
113
- ```ts title="MyComponent.tsx"
114
- import {Injectable, Inject} from 'react-obsidian';
115
- import {ApplicationGraph} from './ApplicationGraph';
116
-
117
- @Injectable(ApplicationGraph)
118
- export MyClassComponent extends React.Component {
119
- @Inject() private fooService!: FooService;
120
-
121
- }
122
- ```
123
-
124
- Render the injected component. Obsidian resolves the required dependencies automatically.
125
- ```tsx title="SomeComponent.tsx"
126
- import MyComponent from './MyComponent';
127
-
128
- const SomeComponent = () => {
129
- // 4. Render the component - its dependencies are resolved automatically by Obsidian.
130
- return <MyComponent />;
131
- }
132
- ```
133
-
134
- </TabItem>
135
- <TabItem value="class" label="Class constructor injection">
136
-
137
- To inject a class, annotate it with the `@Injectable` decorator. The `@Injectable` decorator takes a single parameter - the graph that should be used to resolve the dependencies.
138
- Declare the dependencies as constructor parameters and annotate them with the `@Inject` decorator.
139
-
140
- ```ts title="MyClass.tsx"
141
- import {Injectable, Inject} from 'react-obsidian';
142
- import {ApplicationGraph} from './ApplicationGraph';
143
-
144
- @Injectable(ApplicationGraph)
145
- export MyClass {
146
- constructor (fooService?: FooService);
147
- constructor(@Inject() private fooService: FooService) { }
148
- }
149
- ```
150
-
151
- Now we can use the injected class without providing its dependencies manually:
152
- ```ts
153
- const myClass = new MyClass();
154
- ```
155
-
156
- Of course, passing dependencies explicitly is still possible:
157
- ```ts
158
- const myClass = new MyClass(new FooService());
159
- ```
160
-
161
- </TabItem>
162
- </Tabs>
163
-
164
- ___
165
-
166
- ## Features
167
-
168
- * ⚛️ Inject all React constructs
169
- * Functional components
170
- * Hooks
171
- * Class components
172
- * 🛠 Improve code structure
173
- * Easily write object-oriented code with Single Responsibility in mind
174
- * Eliminate circular dependencies
175
- * Avoid implicit dependencies to make your code easier to reason about
176
- * ❤️ Developer experience
177
- * Seamlessly integrates into existing projects
178
- * Easy to adopt gradually
179
- * Scales well
180
- * Idiomatic API that's easy to understand
181
-
182
- ## Design principles
183
-
184
- React Obsidian is guided by the principles of the Dependency Injection pattern, but does not strictly follow them. We allowed ourselves a degree of freedom when designing the library in order to reduce boilerplate code and library footprint.
185
-
186
- * **Easy to start** - Obsidian requires very little code to get you started. Once you declare a graph, using it to inject dependencies requires as little as two lines of code.
187
- * **Intuitive API** - The API should be verbose and understandable even to new users without prior experience with Dependency Injection.
188
- * **Minimal boilerplate** - Require the bare minimum in order to construct dependencies and resolve them.
189
-
190
- <!-- ## Comparison with other libraries -->
@@ -1,56 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # Installation
6
-
7
- Like most Dependency Injection frameworks, Obsidian uses automatic code generation to create the bindings necessary for resolving dependencies. This approach helps reduce the amount of boilerplate code required by developers. Obsidian relies on Babel for code generation, so you'll need to have Babel configured in your project.
8
-
9
- ## 1. Install Obsidian
10
-
11
- ```bash
12
- npm install react-obsidian
13
- ```
14
-
15
- ## 2. Install Reflect-metadata
16
- First, install and enable the reflect-metadata polyfill.
17
- ```bash
18
- npm install reflect-metadata
19
- ```
20
-
21
- Then, add the following line to the top of your application's entry point (usually index.js or index.ts):
22
- ```js
23
- import 'reflect-metadata';
24
- ```
25
-
26
- ## 3. Enable experimental decorators
27
- Obsidian uses the Decorators feature whose proposal is at stage 3.
28
-
29
- Add the following options to your tsconfig.json file.
30
-
31
- ```js
32
- {
33
- "compilerOptions": {
34
- "experimentalDecorators": true,
35
- "emitDecoratorMetadata": true
36
- }
37
- }
38
- ```
39
-
40
- ## 4. Add the required Babel plugins
41
- Add the transformer to the list of plugins in your `.babel` file.
42
-
43
- ```diff
44
- module.exports = {
45
- presets: [
46
- 'module:metro-react-native-babel-preset',
47
- + ['@babel/preset-typescript', {'onlyRemoveTypeImports': true}]
48
- ],
49
- plugins: [
50
- + react-obsidian/dist/transformers/babel-plugin-obsidian,
51
- + ['@babel/plugin-proposal-decorators', {legacy: true}],
52
- + '@babel/plugin-transform-class-properties',
53
- + 'babel-plugin-parameter-decorator'
54
- ]
55
- };
56
- ```
@@ -1,13 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- title: "Clearing graphs"
4
- ---
5
-
6
- Graphs can be cleared by invoking the `Obsidian.clearGraphs()` function. This is useful in tests or when you need to reset the system to it's original state, for example after a user logs out.
7
-
8
- #### Clearing graphs automatically during execution of Jest tests
9
- Create a `jest.setup.js` file and add it to [setupFilesAfterEnv](https://jestjs.io/docs/configuration#setupfilesafterenv-array). Then, import the following file when ensures graphs are cleared before each test.
10
-
11
- ```js
12
- import 'react-obsidian/clearGraphs';
13
- ```
@@ -1,27 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- title: "Graph middlewares"
4
- ---
5
-
6
- Graph middlewares let you plug into the graph creation process and modify the graph in any way you want. This is useful when working on large scale applications where "observability" is a key concern. For example, you can use a middleware to swizzle providers, add logging, or even add a new provider to the graph.
7
-
8
- Middleware follow the Chain of Responsibility pattern and therefore must always return a graph, either by creating one explicitly or by returning the instance created by another member in the resolve chain.
9
-
10
- ## Example: adding a logging middleware
11
- The following example demonstrates how to add a middleware that's used for logging purposes.
12
-
13
- ```ts
14
- import { GraphMiddleware } from 'react-obsidian';
15
-
16
- const loggingMiddleware = new class extends GraphMiddleware {
17
- resolve<Props>(resolveChain: GraphResolveChain, Graph: Constructable<T>, props?: Props) {
18
- const t1 = Date.now();
19
- const graph = resolveChain.proceed(Graph, props);
20
- const t2 = Date.now();
21
- console.log(`Graph created in ${t2 - t1} milliseconds`);
22
- return graph;
23
- }
24
- }();
25
-
26
- Obsidian.addGraphMiddleware(loggingMiddleware);
27
- ```
@@ -1,18 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- title: "Class components"
4
- ---
5
-
6
- ## Injecting class components
7
- Injecting class components is a two step process. First, annotate the class with the `@Injectable` annotation and pass the graph from which dependencies should be resolve. Then, declare the dependencies as class members and annotate them with the `@Inject` annotation.
8
-
9
- ```ts
10
- import {Injectable, Inject} from 'react-obsidian';
11
- import {ApplicationGraph} from './ApplicationGraph';
12
-
13
- @Injectable(ApplicationGraph)
14
- export class ClassComponent extends React.Component {
15
- @Inject() private httpClient!: HttpClient;
16
-
17
- }
18
- ```
@@ -1,41 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- title: "Classes"
4
- ---
5
-
6
- ## Injecting classes
7
- Injecting classes is a two step process. First, annotate the class with the `@Injectable` annotation and pass the graph from which dependencies should be resolve. Then, declare the dependencies as class members and annotate them with the `@Inject` annotation.
8
-
9
- ```ts
10
- import {Injectable, Inject} from 'react-obsidian';
11
- import {ApplicationGraph} from './ApplicationGraph';
12
-
13
- @Injectable(ApplicationGraph)
14
- export class MyClass {
15
- @Inject() private httpClient!: HttpClient;
16
-
17
- }
18
- ```
19
-
20
- :::important Always prefer constructor injection over field injection
21
- Constructor injection is the preferred way to inject dependencies. It is more explicit and easier to test. **Field injection should only be used when a class is not instantiated by a graph.**
22
- :::
23
-
24
- ## Delayed injection
25
- Dependencies annotated with the `@Inject` annotation are resolved immediately **after** the constructor is called. If you want to inject a class at a later point in time, you can use the `@LateInject` annotation instead, and inject the dependencies by manually with the `Obsidian.inject()` function.
26
-
27
- ```ts
28
- import {Injectable, LateInject} from 'react-obsidian';
29
- import {ApplicationGraph} from './ApplicationGraph';
30
-
31
- @Injectable(ApplicationGraph)
32
- export class MyClass {
33
- @LateInject() private httpClient!: HttpClient;
34
-
35
- public init() {
36
- console.log(this.httpClient === undefined); // true
37
- Obsidian.inject(this);
38
- console.log(this.httpClient === undefined); // false
39
- }
40
- }
41
- ```